Skip to content
This repository was archived by the owner on Dec 23, 2021. It is now read-only.

Commit 0dec72d

Browse files
committed
Establish connection for debug adapter and webview with the messaging service
1 parent b616a7d commit 0dec72d

File tree

5 files changed

+37
-3
lines changed

5 files changed

+37
-3
lines changed

src/extension_utils/debugAdapter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ export class DebugAdapter implements DebugAdapterTracker {
2828
console.log(JSON.stringify(message));
2929
if (message.command) {
3030
// Only send pertinent debug messages
31+
console.log("command exists")
32+
console.log(message.command)
3133

32-
if (message.command in DEBUG_COMMANDS) {
34+
if (Object.values(DEBUG_COMMANDS).includes(message.command)) {
3335
this.handleAdapterMessages(message.command);
3436
}
3537
}

src/view/App.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@ import {
77
DEVICE_LIST_KEY,
88
VSCODE_MESSAGES_TO_WEBVIEW,
99
DEBUG_COMMANDS,
10+
VIEW_STATE,
1011
} from "./constants";
1112
import { Device } from "./container/device/Device";
13+
import {ViewStateContext} from './context'
1214

1315
interface IState {
1416
currentDevice: string;
17+
viewState:VIEW_STATE;
1518
}
1619

1720
const defaultState = {
1821
currentDevice: DEVICE_LIST_KEY.CPX,
22+
viewState:VIEW_STATE.RUNNING
1923
};
2024

25+
26+
27+
2128
class App extends React.Component<{}, IState> {
2229
constructor() {
2330
super({});
@@ -43,23 +50,29 @@ class App extends React.Component<{}, IState> {
4350
return (
4451
<div className="App">
4552
<main className="App-main">
53+
<ViewStateContext.Provider value ={this.state.viewState}>
4654
<Device currentSelectedDevice={this.state.currentDevice} />
47-
</main>
55+
</ViewStateContext.Provider></main>
4856
</div>
4957
);
5058
}
5159

5260
handleMessage = (event: any): void => {
5361
const message = event.data;
54-
console.log(JSON.stringify(message));
62+
console.log(
63+
"blabla"+JSON.stringify(message));
5564
switch (message.command) {
5665
case VSCODE_MESSAGES_TO_WEBVIEW.SET_DEVICE:
5766
if (message.active_device !== this.state.currentDevice) {
5867
this.setState({ currentDevice: message.active_device });
5968
}
6069
break;
6170
case DEBUG_COMMANDS.CONTINUE:
71+
this.setState({viewState:VIEW_STATE.RUNNING})
72+
break;
6273
case DEBUG_COMMANDS.STACK_TRACE:
74+
this.setState({viewState:VIEW_STATE.PAUSE})
75+
6376
break;
6477
}
6578
};

src/view/components/Button.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as React from "react";
22
import "../styles/Button.css";
3+
import {ViewStateContext} from '../context'
4+
import { VIEW_STATE } from "../constants";
35

46
export interface IButtonProps {
57
label: string;
@@ -15,6 +17,9 @@ const Button: React.FC<IButtonProps> = props => {
1517
const iconSvg: SVGElement = props.image as SVGElement;
1618
const buttonStyle = { width: props.width };
1719
const tabIndex = props.focusable ? 0 : -1;
20+
const isButtonDisabled = (React.useContext(ViewStateContext) === VIEW_STATE.PAUSE)
21+
console.log(React.useContext(ViewStateContext))
22+
console.log(isButtonDisabled)
1823

1924
return (
2025
<button
@@ -25,6 +30,7 @@ const Button: React.FC<IButtonProps> = props => {
2530
onClick={props.onClick}
2631
style={buttonStyle}
2732
tabIndex={tabIndex}
33+
disabled={isButtonDisabled}
2834
>
2935
{iconSvg}
3036
</button>

src/view/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ export enum DEVICE_LIST_KEY {
5555
MICROBIT = "micro:bit",
5656
}
5757

58+
// Pauses on Debug mode alter the state of the view
59+
export enum VIEW_STATE{
60+
PAUSE="debug-pause",
61+
RUNNING="running"
62+
}
63+
5864
//
5965
export enum WEBVIEW_MESSAGES {
6066
SWITCH_DEVICE = "switch-device",

src/view/context.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import * as React from "react";
2+
import { VIEW_STATE } from "./constants";
3+
4+
// View is running by default
5+
6+
export const ViewStateContext = React.createContext(
7+
VIEW_STATE.RUNNING )

0 commit comments

Comments
 (0)