From 9828f41bb1f246b1c4dd1fc00dc000ab5a1d8017 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Thu, 13 Feb 2020 09:16:37 -0800 Subject: [PATCH 1/5] Load device on boot --- src/debuggerCommunicationServer.ts | 6 +++++- src/extension.ts | 9 ++++++--- src/view/App.tsx | 8 ++++++++ src/view/index.tsx | 1 - 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/debuggerCommunicationServer.ts b/src/debuggerCommunicationServer.ts index 76eb02f42..5ad66d18f 100644 --- a/src/debuggerCommunicationServer.ts +++ b/src/debuggerCommunicationServer.ts @@ -11,10 +11,12 @@ export class DebuggerCommunicationServer { private serverHttp: http.Server; private serverIo: socketio.Server; private simulatorWebview: WebviewPanel | undefined; + private currentActiveDevice; constructor( webviewPanel: WebviewPanel | undefined, - port = SERVER_INFO.DEFAULT_SERVER_PORT + port = SERVER_INFO.DEFAULT_SERVER_PORT, + currentActiveDevice:string ) { this.port = port; this.serverHttp = new http.Server(); @@ -24,6 +26,8 @@ export class DebuggerCommunicationServer { this.simulatorWebview = webviewPanel; this.initEventsHandlers(); console.info(`Server running on port ${this.port}`); + + this.currentActiveDevice=currentActiveDevice } public closeConnection(): void { diff --git a/src/extension.ts b/src/extension.ts index 463320436..dd0df5359 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -41,7 +41,7 @@ let currentActiveDevice: string = DEFAULT_DEVICE; export let outChannel: vscode.OutputChannel | undefined; function loadScript(context: vscode.ExtensionContext, scriptPath: string) { - return ``; } @@ -138,6 +138,7 @@ export async function activate(context: vscode.ExtensionContext) { enableScripts: true, } ); + currentPanel.webview.html = getWebviewContent(context); @@ -915,7 +916,8 @@ export async function activate(context: vscode.ExtensionContext) { debuggerCommunicationHandler = new DebuggerCommunicationServer( currentPanel, - utils.getServerPortConfig() + utils.getServerPortConfig(), + currentActiveDevice ); openWebview(); if (currentPanel) { @@ -1137,9 +1139,10 @@ function getWebviewContent(context: vscode.ExtensionContext) {
- + ${loadScript(context, "out/vendor.js")} ${loadScript(context, "out/simulator.js")} diff --git a/src/view/App.tsx b/src/view/App.tsx index cff908a5a..c8bff087b 100644 --- a/src/view/App.tsx +++ b/src/view/App.tsx @@ -28,6 +28,14 @@ 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() { diff --git a/src/view/index.tsx b/src/view/index.tsx index 9b0fc44a2..32e7400b1 100644 --- a/src/view/index.tsx +++ b/src/view/index.tsx @@ -14,7 +14,6 @@ const locale = "en"; const message = { en: messageEn, }; - ReactDOM.render( From ecbaa381d0046c47b3767563881a7fd3c281e372 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Fri, 14 Feb 2020 09:55:31 -0800 Subject: [PATCH 2/5] Formatting app --- src/view/App.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/view/App.tsx b/src/view/App.tsx index c8bff087b..3e96b0adf 100644 --- a/src/view/App.tsx +++ b/src/view/App.tsx @@ -29,11 +29,12 @@ class App extends React.Component<{}, IState> { } componentDidMount() { if (document.currentScript) { - const initialDevice = document.currentScript.getAttribute('initialDevice') + const initialDevice = document.currentScript.getAttribute( + "initialDevice" + ); if (initialDevice) { - this.setState({ currentDevice: initialDevice }) - + this.setState({ currentDevice: initialDevice }); } } window.addEventListener("message", this.handleMessage); From 2e9634033ade4d17be0121fba613439289e1f6ca Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Fri, 14 Feb 2020 10:25:59 -0800 Subject: [PATCH 3/5] Remove unused attribute to debug server --- src/debuggerCommunicationServer.ts | 6 +----- src/extension.ts | 5 +++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/debuggerCommunicationServer.ts b/src/debuggerCommunicationServer.ts index 5ad66d18f..76eb02f42 100644 --- a/src/debuggerCommunicationServer.ts +++ b/src/debuggerCommunicationServer.ts @@ -11,12 +11,10 @@ export class DebuggerCommunicationServer { private serverHttp: http.Server; private serverIo: socketio.Server; private simulatorWebview: WebviewPanel | undefined; - private currentActiveDevice; constructor( webviewPanel: WebviewPanel | undefined, - port = SERVER_INFO.DEFAULT_SERVER_PORT, - currentActiveDevice:string + port = SERVER_INFO.DEFAULT_SERVER_PORT ) { this.port = port; this.serverHttp = new http.Server(); @@ -26,8 +24,6 @@ export class DebuggerCommunicationServer { this.simulatorWebview = webviewPanel; this.initEventsHandlers(); console.info(`Server running on port ${this.port}`); - - this.currentActiveDevice=currentActiveDevice } public closeConnection(): void { diff --git a/src/extension.ts b/src/extension.ts index dd0df5359..65c02ef6c 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -41,7 +41,9 @@ let currentActiveDevice: string = DEFAULT_DEVICE; export let outChannel: vscode.OutputChannel | undefined; function loadScript(context: vscode.ExtensionContext, scriptPath: string) { - return ``; } @@ -138,7 +140,6 @@ export async function activate(context: vscode.ExtensionContext) { enableScripts: true, } ); - currentPanel.webview.html = getWebviewContent(context); From 395c2666e1aa872409f9115bcf4ae0a1d0b1cf08 Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Fri, 14 Feb 2020 13:21:35 -0800 Subject: [PATCH 4/5] Remove unused script tag --- src/extension.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 65c02ef6c..42d289240 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -917,8 +917,8 @@ export async function activate(context: vscode.ExtensionContext) { debuggerCommunicationHandler = new DebuggerCommunicationServer( currentPanel, - utils.getServerPortConfig(), - currentActiveDevice + utils.getServerPortConfig() + ); openWebview(); if (currentPanel) { @@ -1143,7 +1143,6 @@ function getWebviewContent(context: vscode.ExtensionContext) { - ${loadScript(context, "out/vendor.js")} ${loadScript(context, "out/simulator.js")} From 3de8c7f702a2762bd1cb616b42d5e723d063fc5c Mon Sep 17 00:00:00 2001 From: xnkevinnguyen Date: Fri, 14 Feb 2020 13:45:55 -0800 Subject: [PATCH 5/5] Format extension --- src/extension.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index 42d289240..f195fcab4 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -918,7 +918,6 @@ export async function activate(context: vscode.ExtensionContext) { debuggerCommunicationHandler = new DebuggerCommunicationServer( currentPanel, utils.getServerPortConfig() - ); openWebview(); if (currentPanel) {