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:
2025-11-24 23:04:37 +09:00
parent 82cf4b8fd0
commit 83a9a63de4
2 changed files with 12 additions and 12 deletions

View File

@@ -13,7 +13,7 @@ class CommunicationLayer {
if (isWebView) { if (isWebView) {
console.log("[COMM] Running in WebView2 Mode"); console.log("[COMM] Running in WebView2 Mode");
this.isConnected = true; // WebView2 is always connected 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); this.notifyListeners(event.data);
}); });
} else { } else {
@@ -71,7 +71,7 @@ class CommunicationLayer {
public async getConfig(): Promise<string> { public async getConfig(): Promise<string> {
if (isWebView) { if (isWebView) {
return await window.chrome.webview.hostObjects.machine.GetConfig(); return await window.chrome!.webview!.hostObjects.machine.GetConfig();
} else { } else {
// WebSocket Request/Response Pattern // WebSocket Request/Response Pattern
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@@ -104,7 +104,7 @@ class CommunicationLayer {
public async getIOList(): Promise<string> { public async getIOList(): Promise<string> {
if (isWebView) { if (isWebView) {
return await window.chrome.webview.hostObjects.machine.GetIOList(); return await window.chrome!.webview!.hostObjects.machine.GetIOList();
} else { } else {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!this.isConnected) { if (!this.isConnected) {
@@ -133,7 +133,7 @@ class CommunicationLayer {
public async getRecipeList(): Promise<string> { public async getRecipeList(): Promise<string> {
if (isWebView) { if (isWebView) {
return await window.chrome.webview.hostObjects.machine.GetRecipeList(); return await window.chrome!.webview!.hostObjects.machine.GetRecipeList();
} else { } else {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!this.isConnected) { if (!this.isConnected) {
@@ -162,7 +162,7 @@ class CommunicationLayer {
public async saveConfig(configJson: string): Promise<void> { public async saveConfig(configJson: string): Promise<void> {
if (isWebView) { if (isWebView) {
await window.chrome.webview.hostObjects.machine.SaveConfig(configJson); await window.chrome!.webview!.hostObjects.machine.SaveConfig(configJson);
} else { } else {
this.ws?.send(JSON.stringify({ type: 'SAVE_CONFIG', data: JSON.parse(configJson) })); this.ws?.send(JSON.stringify({ type: 'SAVE_CONFIG', data: JSON.parse(configJson) }));
} }
@@ -170,7 +170,7 @@ class CommunicationLayer {
public async sendControl(command: string) { public async sendControl(command: string) {
if (isWebView) { if (isWebView) {
await window.chrome.webview.hostObjects.machine.SystemControl(command); await window.chrome!.webview!.hostObjects.machine.SystemControl(command);
} else { } else {
this.ws?.send(JSON.stringify({ type: 'CONTROL', command })); this.ws?.send(JSON.stringify({ type: 'CONTROL', command }));
} }
@@ -178,7 +178,7 @@ class CommunicationLayer {
public async moveAxis(axis: string, value: number) { public async moveAxis(axis: string, value: number) {
if (isWebView) { if (isWebView) {
await window.chrome.webview.hostObjects.machine.MoveAxis(axis, value); await window.chrome!.webview!.hostObjects.machine.MoveAxis(axis, value);
} else { } else {
this.ws?.send(JSON.stringify({ type: 'MOVE', axis, value })); this.ws?.send(JSON.stringify({ type: 'MOVE', axis, value }));
} }
@@ -186,7 +186,7 @@ class CommunicationLayer {
public async setIO(id: number, state: boolean) { public async setIO(id: number, state: boolean) {
if (isWebView) { if (isWebView) {
await window.chrome.webview.hostObjects.machine.SetIO(id, false, state); await window.chrome!.webview!.hostObjects.machine.SetIO(id, false, state);
} else { } else {
this.ws?.send(JSON.stringify({ type: 'SET_IO', id, state })); 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 }> { public async selectRecipe(recipeId: string): Promise<{ success: boolean; message: string; recipeId?: string }> {
if (isWebView) { 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); return JSON.parse(resultJson);
} else { } else {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {

View File

@@ -52,14 +52,14 @@ export interface ConfigItem {
declare global { declare global {
interface Window { interface Window {
chrome: { chrome?: {
webview: { webview?: {
hostObjects: { hostObjects: {
machine: { machine: {
MoveAxis(axis: string, value: number): Promise<void>; MoveAxis(axis: string, value: number): Promise<void>;
SetIO(id: number, isInput: boolean, state: boolean): Promise<void>; SetIO(id: number, isInput: boolean, state: boolean): Promise<void>;
SystemControl(command: string): Promise<void>; SystemControl(command: string): Promise<void>;
LoadRecipe(recipeId: string): Promise<void>; SelectRecipe(recipeId: string): Promise<string>;
GetConfig(): Promise<string>; GetConfig(): Promise<string>;
GetIOList(): Promise<string>; GetIOList(): Promise<string>;
GetRecipeList(): Promise<string>; GetRecipeList(): Promise<string>;