diff --git a/src/services/wiki/index.ts b/src/services/wiki/index.ts index 1ae6d2bd..dc289f73 100644 --- a/src/services/wiki/index.ts +++ b/src/services/wiki/index.ts @@ -517,12 +517,22 @@ export class Wiki implements IWikiService { if (!syncOnlyWhenNoDraft) { return true; } - const draftTitles = await this.wikiOperation(WikiChannel.runFilter, id, '[is[draft]]'); - // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions - if (Array.isArray(draftTitles) && draftTitles.length > 0) { - return false; + try { + const draftTitles = await this.wikiOperation(WikiChannel.runFilter, id, '[is[draft]]'); + // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions + if (Array.isArray(draftTitles) && draftTitles.length > 0) { + return false; + } + return true; + } catch (error) { + logger.error( + `${(error as Error).message} when checking draft titles. ${ + (error as Error).stack ?? '' + }\n This might because it just will throw error when on Windows and App is at background (BrowserView will disappear and not accessible.)`, + ); + // when app is on background, might have no draft, because user won't edit it. So just return true + return true; } - return true; }; const userInfo = await this.authService.getStorageServiceUserInfo(storageService); diff --git a/src/services/wiki/wikiOperations.ts b/src/services/wiki/wikiOperations.ts index 5996ab27..9302096d 100644 --- a/src/services/wiki/wikiOperations.ts +++ b/src/services/wiki/wikiOperations.ts @@ -21,7 +21,10 @@ function sendToMainWindowNoWait(type: WikiChannel, workspaceID: string, messages browserView?.webContents?.send?.(type, ...messages); } /** - * Send to main window renderer (preload script) and wait for response + * Send to main window renderer (preload script) and wait for response. + * + * Will throw error when on Windows and App is at background (BrowserView will disappear and not accessible.) https://github.com/tiddly-gittly/TidGi-Desktop/issues/398 + * * @param type The handler on renderer (preload script) side should implement `ipcRenderer.send(WikiChannel.xxx, nonceReceived, result);`, where `result` is usually `string[]` (the default type for `` in function signature) * @returns undefined if main window webContents is not found */