From cab9445032b8bd90f914213cb38bc35c2633aaeb Mon Sep 17 00:00:00 2001 From: Kuingsmile <96409857+Kuingsmile@users.noreply.github.com> Date: Mon, 2 Feb 2026 09:24:37 +0800 Subject: [PATCH] :bug: Fix(custom): fix the issue of webcontents --- src/main/apis/gui/index.ts | 2 +- src/main/events/rpc/routes/tray/index.ts | 4 ++-- src/main/utils/uploadTaskQueue.ts | 6 +----- src/renderer/pages/PicGoSetting.vue | 2 +- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/apis/gui/index.ts b/src/main/apis/gui/index.ts index 4596696e..bf9b5c4b 100644 --- a/src/main/apis/gui/index.ts +++ b/src/main/apis/gui/index.ts @@ -74,7 +74,7 @@ class GuiApi implements IGuiApi { this.windowId = await getWindowId() const webContents = this.getWebcontentsByWindowId(this.windowId) const rawInput = cloneDeep(input) - const res = await uploader.setWebContents(webContents!).uploadReturnCtx(input) + const res = await uploader.setWebContents(webContents).uploadReturnCtx(input) const imgs = res.ctx?.output ? res.ctx.output : false const backImgs = res.backupCtx?.output ? res.backupCtx.output : false let result: ImgInfo[] = [] diff --git a/src/main/events/rpc/routes/tray/index.ts b/src/main/events/rpc/routes/tray/index.ts index 55586074..fa2a82be 100644 --- a/src/main/events/rpc/routes/tray/index.ts +++ b/src/main/events/rpc/routes/tray/index.ts @@ -56,13 +56,13 @@ const trayRoutes = [ await GalleryDB.getInstance().insert(img[0]) trayWindow?.webContents.send('clipboardFiles', []) if (windowManager.has(IWindowList.SETTING_WINDOW)) { - windowManager.get(IWindowList.SETTING_WINDOW)!.webContents.send('updateGallery') + windowManager.get(IWindowList.SETTING_WINDOW)?.webContents.send('updateGallery') } if (backupImgs && backupImgs.length > 0) { await GalleryDB.getInstance().insert(backupImgs[0]) trayWindow?.webContents.send('uploadFiles') if (windowManager.has(IWindowList.SETTING_WINDOW)) { - windowManager.get(IWindowList.SETTING_WINDOW)!.webContents?.send('updateGallery') + windowManager.get(IWindowList.SETTING_WINDOW)?.webContents?.send('updateGallery') } } } diff --git a/src/main/utils/uploadTaskQueue.ts b/src/main/utils/uploadTaskQueue.ts index 158a941c..8145fab4 100644 --- a/src/main/utils/uploadTaskQueue.ts +++ b/src/main/utils/uploadTaskQueue.ts @@ -71,7 +71,7 @@ class UploadTaskQueueManager { maxRetryCount: 3, } - private webContents: WebContents | null = null + private webContents: WebContents | undefined = undefined private persistPath = path.join(dataDir(), 'taskQueue.json') private taskTimer: NodeJS.Timeout | null = null @@ -230,10 +230,6 @@ class UploadTaskQueueManager { const win = windowManager.getAvailableWindow() const webContents = this.webContents || win?.webContents - if (!webContents) { - throw new Error('No webContents available for upload') - } - const input = [task.filePath] const rawInput = cloneDeep(input) diff --git a/src/renderer/pages/PicGoSetting.vue b/src/renderer/pages/PicGoSetting.vue index 8d0140ef..189c4caf 100644 --- a/src/renderer/pages/PicGoSetting.vue +++ b/src/renderer/pages/PicGoSetting.vue @@ -39,7 +39,7 @@