Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions src/app-inspector/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</head>
<body style="height: 100vh; margin: 0">
<div id="root" style="height: 100%; display: flex; flex-direction: column"></div>
<script>window.__APP_INSPECTOR_CONTEXT__ = null;</script>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
<script>window.__APP_INSPECTOR_CONTEXT__ = null;</script>
<script>window.__APP_INSPECTOR_CONTEXT__ = undefined;</script>

<script type="module" src="./main.tsx"></script>
</body>
</html>
20 changes: 20 additions & 0 deletions src/app-inspector/main.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { DeploymentContainer } from "@localstack/appinspector-ui";
import {
AppInspectorContextProvider,
pages,
Expand All @@ -14,8 +15,26 @@ import {
Routes,
} from "react-router-dom";

/* Passed by the VS Code extension when App Inspector is launched. */
declare global {
interface Window {
__APP_INSPECTOR_CONTEXT__: {
source: "vscode";
ideVersion: string;
extensionVersion: string;
} | null;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
} | null;
} | undefined;

}
}

const APPINSPECTOR_ROUTE_PREFIX = "/appinspector";

const deploymentContainer: DeploymentContainer =
window.__APP_INSPECTOR_CONTEXT__ ?? {
source: "vscode",
ideVersion: "unknown",
extensionVersion: "unknown",
};

render(
<StrictMode>
<div style={{ display: "flex", flexDirection: "column", height: "100%" }}>
Expand All @@ -29,6 +48,7 @@ render(
>
<LocalStackThemeProvider useExtensionLayout={false}>
<AppInspectorContextProvider
deploymentContainer={deploymentContainer}
linkComponent={(props) => (
<Link to={props.to}>{props.children}</Link>
)}
Expand Down
25 changes: 20 additions & 5 deletions src/plugins/app-inspector-webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
TreeItem,
TreeItemCollapsibleState,
Uri,
extensions,
version as vscodeVersion,
} from "vscode";
import type {
ProviderResult,
Expand Down Expand Up @@ -61,9 +63,15 @@ export default createPlugin(
"utf-8",
);
outputChannel.debug(`html=${html}`);
panel.webview.html = html.replaceAll(
/"(\/.*?\.(?:js|css))"/g,
(_, asset: string) => {
const extensionVersion =
(
extensions.getExtension("localstack.localstack")?.packageJSON as {
version?: string;
}
)?.version ?? "unknown";

panel.webview.html = html
.replaceAll(/"(\/.*?\.(?:js|css))"/g, (_, asset: string) => {
return JSON.stringify(
panel.webview
.asWebviewUri(
Expand All @@ -75,8 +83,15 @@ export default createPlugin(
)
.toString(),
);
},
);
})
.replace(
"window.__APP_INSPECTOR_CONTEXT__ = null;",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
"window.__APP_INSPECTOR_CONTEXT__ = null;",
"window.__APP_INSPECTOR_CONTEXT__ = undefined;",

`window.__APP_INSPECTOR_CONTEXT__ = ${JSON.stringify({
source: "vscode",
ideVersion: vscodeVersion,
extensionVersion,
})};`,
);
outputChannel.debug(`html=${panel.webview.html}`);
}),
);
Expand Down
Loading