diff --git a/frontend/communication.ts b/frontend/communication.ts index 0f39398..2593a66 100644 --- a/frontend/communication.ts +++ b/frontend/communication.ts @@ -13,7 +13,7 @@ class CommunicationLayer { if (isWebView) { console.log("[COMM] Running in WebView2 Mode"); this.isConnected = true; // WebView2 is always connected - window.chrome.webview.addEventListener('message', (event: any) => { + window.chrome!.webview!.addEventListener('message', (event: any) => { this.notifyListeners(event.data); }); } else { @@ -71,7 +71,7 @@ class CommunicationLayer { public async getConfig(): Promise { if (isWebView) { - return await window.chrome.webview.hostObjects.machine.GetConfig(); + return await window.chrome!.webview!.hostObjects.machine.GetConfig(); } else { // WebSocket Request/Response Pattern return new Promise((resolve, reject) => { @@ -104,7 +104,7 @@ class CommunicationLayer { public async getIOList(): Promise { if (isWebView) { - return await window.chrome.webview.hostObjects.machine.GetIOList(); + return await window.chrome!.webview!.hostObjects.machine.GetIOList(); } else { return new Promise((resolve, reject) => { if (!this.isConnected) { @@ -133,7 +133,7 @@ class CommunicationLayer { public async getRecipeList(): Promise { if (isWebView) { - return await window.chrome.webview.hostObjects.machine.GetRecipeList(); + return await window.chrome!.webview!.hostObjects.machine.GetRecipeList(); } else { return new Promise((resolve, reject) => { if (!this.isConnected) { @@ -162,7 +162,7 @@ class CommunicationLayer { public async saveConfig(configJson: string): Promise { if (isWebView) { - await window.chrome.webview.hostObjects.machine.SaveConfig(configJson); + await window.chrome!.webview!.hostObjects.machine.SaveConfig(configJson); } else { this.ws?.send(JSON.stringify({ type: 'SAVE_CONFIG', data: JSON.parse(configJson) })); } @@ -170,7 +170,7 @@ class CommunicationLayer { public async sendControl(command: string) { if (isWebView) { - await window.chrome.webview.hostObjects.machine.SystemControl(command); + await window.chrome!.webview!.hostObjects.machine.SystemControl(command); } else { this.ws?.send(JSON.stringify({ type: 'CONTROL', command })); } @@ -178,7 +178,7 @@ class CommunicationLayer { public async moveAxis(axis: string, value: number) { if (isWebView) { - await window.chrome.webview.hostObjects.machine.MoveAxis(axis, value); + await window.chrome!.webview!.hostObjects.machine.MoveAxis(axis, value); } else { this.ws?.send(JSON.stringify({ type: 'MOVE', axis, value })); } @@ -186,7 +186,7 @@ class CommunicationLayer { public async setIO(id: number, state: boolean) { if (isWebView) { - await window.chrome.webview.hostObjects.machine.SetIO(id, false, state); + await window.chrome!.webview!.hostObjects.machine.SetIO(id, false, state); } else { this.ws?.send(JSON.stringify({ type: 'SET_IO', id, state })); } @@ -194,7 +194,7 @@ class CommunicationLayer { public async selectRecipe(recipeId: string): Promise<{ success: boolean; message: string; recipeId?: string }> { if (isWebView) { - const resultJson = await window.chrome.webview.hostObjects.machine.SelectRecipe(recipeId); + const resultJson = await window.chrome!.webview!.hostObjects.machine.SelectRecipe(recipeId); return JSON.parse(resultJson); } else { return new Promise((resolve, reject) => { diff --git a/frontend/types.ts b/frontend/types.ts index f7fab75..f7be9ca 100644 --- a/frontend/types.ts +++ b/frontend/types.ts @@ -52,14 +52,14 @@ export interface ConfigItem { declare global { interface Window { - chrome: { - webview: { + chrome?: { + webview?: { hostObjects: { machine: { MoveAxis(axis: string, value: number): Promise; SetIO(id: number, isInput: boolean, state: boolean): Promise; SystemControl(command: string): Promise; - LoadRecipe(recipeId: string): Promise; + SelectRecipe(recipeId: string): Promise; GetConfig(): Promise; GetIOList(): Promise; GetRecipeList(): Promise;