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 3 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
10 changes: 7 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ 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 @@ -915,7 +917,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 +1140,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