fix: Add TypeScript type definitions for SelectRecipe
- Update Window interface in types.ts to include SelectRecipe method - Change chrome and webview to optional properties (chrome?, webview?) - Add non-null assertions (!) to all window.chrome.webview accesses - Remove LoadRecipe (replaced with SelectRecipe) - Fix TypeScript strict null checking errors 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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<string> {
|
||||
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<string> {
|
||||
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<string> {
|
||||
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<void> {
|
||||
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) => {
|
||||
|
||||
Reference in New Issue
Block a user