|
1 | 1 | import { useState, useEffect } from "react" |
2 | | -import { BrowserRouter as Router, Routes, Route } from "react-router-dom" |
| 2 | +import { MemoryRouter as Router, Routes, Route } from "react-router-dom" |
3 | 3 | import { FluentProvider, webLightTheme, webDarkTheme } from "@fluentui/react-components" |
4 | 4 | import SettingsView from "./components/SettingsView" |
5 | 5 | import "./App.css" |
6 | 6 |
|
7 | 7 | // Define the VS Code API |
8 | 8 | declare global { |
9 | 9 | interface Window { |
10 | | - acquireVsCodeApi?: () => { |
11 | | - postMessage: (message: any) => void |
12 | | - getState: () => any |
13 | | - setState: (state: any) => void |
| 10 | + vscode?: { |
| 11 | + postMessage: (message: unknown) => void |
| 12 | + getState: () => unknown |
| 13 | + setState: (state: unknown) => void |
14 | 14 | } |
15 | 15 | } |
16 | 16 | } |
17 | 17 |
|
18 | | -// Initialize VS Code API |
19 | | -const vscode = (() => { |
20 | | - if (window.acquireVsCodeApi) { |
21 | | - return window.acquireVsCodeApi() |
22 | | - } |
23 | | - |
24 | | - // Fallback for when running outside of VS Code (e.g., in a browser for development) |
25 | | - return { |
26 | | - postMessage: (message: any) => console.log("VS Code message:", message), |
27 | | - getState: () => ({}), |
28 | | - setState: () => {}, |
29 | | - } |
30 | | -})() |
| 18 | +// Use the global vscode object that was set in the HTML |
| 19 | +const vscode = window.vscode || { |
| 20 | + postMessage: (message: unknown) => console.log("VS Code message:", message), |
| 21 | + getState: () => ({}), |
| 22 | + setState: () => {}, |
| 23 | +} |
31 | 24 |
|
32 | 25 | // Define the message type for communication with the extension |
33 | 26 | interface VSCodeMessage { |
@@ -73,7 +66,7 @@ function App() { |
73 | 66 |
|
74 | 67 | return ( |
75 | 68 | <FluentProvider theme={theme}> |
76 | | - <Router> |
| 69 | + <Router initialEntries={["/"]} initialIndex={0}> |
77 | 70 | <div className="app-container"> |
78 | 71 | {!initialized ? ( |
79 | 72 | <div style={{ padding: "20px" }}>Loading settings...</div> |
|
0 commit comments