From 7bdf10050cef7f39b0f485b89ca0445c49116d81 Mon Sep 17 00:00:00 2001 From: Innei Date: Sun, 1 Dec 2024 22:02:23 +0800 Subject: [PATCH] fix(bridge): window call should catch error Signed-off-by: Innei --- apps/main/src/tipc/reader.ts | 3 ++- packages/shared/src/bridge.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/main/src/tipc/reader.ts b/apps/main/src/tipc/reader.ts index 47b0bbb500..751458f2ff 100644 --- a/apps/main/src/tipc/reader.ts +++ b/apps/main/src/tipc/reader.ts @@ -68,7 +68,8 @@ export const readerRoute = { } await tts.setMetadata(input, OUTPUT_FORMAT.WEBM_24KHZ_16BIT_MONO_OPUS).catch((error) => { - return callWindowExpose(window).toast.error(error.message, { + const msg = typeof error === "string" ? error : error.message + return callWindowExpose(window).toast.error(msg || "unknown set voice error", { duration: 1000, }) }) diff --git a/packages/shared/src/bridge.ts b/packages/shared/src/bridge.ts index 15848af7e5..2b8dd8adb3 100644 --- a/packages/shared/src/bridge.ts +++ b/packages/shared/src/bridge.ts @@ -89,7 +89,7 @@ function createProxy(window: BrowserWindow, path: try { return await window.webContents.executeJavaScript( - `globalThis.${PREFIX}?.${methodPath}?.(${args.map((arg) => JSON.stringify(arg)).join(",")})`, + `(async () => { try { return await globalThis.${PREFIX}?.${methodPath}?.(${args.map((arg) => JSON.stringify(arg)).join(",")}) } catch (err) { console.error('Failed to executeJavaScript: ${methodPath}', err) } })()`, ) } catch (err) { console.error(`Failed to executeJavaScript: ${methodPath}`, err)