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

Load device on boot #203

Merged
merged 5 commits into from
Feb 15, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/debuggerCommunicationServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ export class DebuggerCommunicationServer {
private serverHttp: http.Server;
private serverIo: socketio.Server;
private simulatorWebview: WebviewPanel | undefined;
private currentActiveDevice;
xnkevinnguyen marked this conversation as resolved.
Show resolved Hide resolved

constructor(
webviewPanel: WebviewPanel | undefined,
port = SERVER_INFO.DEFAULT_SERVER_PORT
port = SERVER_INFO.DEFAULT_SERVER_PORT,
currentActiveDevice:string
xnkevinnguyen marked this conversation as resolved.
Show resolved Hide resolved
) {
this.port = port;
this.serverHttp = new http.Server();
Expand All @@ -24,6 +26,8 @@ export class DebuggerCommunicationServer {
this.simulatorWebview = webviewPanel;
this.initEventsHandlers();
console.info(`Server running on port ${this.port}`);

this.currentActiveDevice=currentActiveDevice
xnkevinnguyen marked this conversation as resolved.
Show resolved Hide resolved
}

public closeConnection(): void {
Expand Down
9 changes: 6 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let currentActiveDevice: string = DEFAULT_DEVICE;
export let outChannel: vscode.OutputChannel | undefined;

function loadScript(context: vscode.ExtensionContext, scriptPath: string) {
return `<script src="${vscode.Uri.file(context.asAbsolutePath(scriptPath))
return `<script initialDevice=${currentActiveDevice} src="${vscode.Uri.file(context.asAbsolutePath(scriptPath))
.with({ scheme: "vscode-resource" })
.toString()}"></script>`;
}
Expand Down Expand Up @@ -138,6 +138,7 @@ export async function activate(context: vscode.ExtensionContext) {
enableScripts: true,
}
);


currentPanel.webview.html = getWebviewContent(context);

Expand Down Expand Up @@ -915,7 +916,8 @@ export async function activate(context: vscode.ExtensionContext) {

debuggerCommunicationHandler = new DebuggerCommunicationServer(
currentPanel,
utils.getServerPortConfig()
utils.getServerPortConfig(),
currentActiveDevice
);
openWebview();
if (currentPanel) {
Expand Down Expand Up @@ -1137,9 +1139,10 @@ function getWebviewContent(context: vscode.ExtensionContext) {
</head>
<body>
<div id="root"></div>
<script>
<script >
const vscode = acquireVsCodeApi();
</script>
<script ></script>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this empty block for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used! Removed

${loadScript(context, "out/vendor.js")}
${loadScript(context, "out/simulator.js")}
</body>
Expand Down
9 changes: 9 additions & 0 deletions src/view/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ class App extends React.Component<{}, IState> {
this.state = defaultState;
}
componentDidMount() {
if (document.currentScript) {
const initialDevice = document.currentScript.getAttribute(
"initialDevice"
);

if (initialDevice) {
this.setState({ currentDevice: initialDevice });
}
}
window.addEventListener("message", this.handleMessage);
}
componentWillUnmount() {
Expand Down
1 change: 0 additions & 1 deletion src/view/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const locale = "en";
const message = {
en: messageEn,
};

ReactDOM.render(
<IntlProvider locale={locale} messages={message[locale]}>
<App />
Expand Down