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

Commit

Permalink
Load correct device on new file command (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
xnkevinnguyen authored Feb 15, 2020
1 parent 8891bf5 commit e3fb24c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 4 additions & 2 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 @@ -1137,7 +1139,7 @@ function getWebviewContent(context: vscode.ExtensionContext) {
</head>
<body>
<div id="root"></div>
<script>
<script >
const vscode = acquireVsCodeApi();
</script>
${loadScript(context, "out/vendor.js")}
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

0 comments on commit e3fb24c

Please sign in to comment.