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

Commit

Permalink
Load device into script tag for initial open
Browse files Browse the repository at this point in the history
  • Loading branch information
xnkevinnguyen committed Feb 13, 2020
1 parent 997719d commit f657255
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
5 changes: 4 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;

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();
Expand All @@ -25,6 +27,7 @@ export class DebuggerCommunicationServer {
this.initEventsHandlers();
console.info(`Server running on port ${this.port}`);

this.currentActiveDevice=currentActiveDevice
}

public closeConnection(): void {
Expand Down
8 changes: 5 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 @@ -918,7 +919,7 @@ export async function activate(context: vscode.ExtensionContext) {
debuggerCommunicationHandler = new DebuggerCommunicationServer(
currentPanel,
utils.getServerPortConfig(),

currentActiveDevice
);
openWebview();
if (currentPanel) {
Expand Down Expand Up @@ -1140,9 +1141,10 @@ function getWebviewContent(context: vscode.ExtensionContext) {
</head>
<body>
<div id="root"></div>
<script>
<script >
const vscode = acquireVsCodeApi();
</script>
<script ></script>
${loadScript(context, "out/vendor.js")}
${loadScript(context, "out/simulator.js")}
</body>
Expand Down
8 changes: 8 additions & 0 deletions src/view/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
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

0 comments on commit f657255

Please sign in to comment.