mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-01-25 05:51:04 -08:00
fix: sendToMainWindowAndAwait error when app on background
fixes #398 #396 browserView.webContents is undefined
This commit is contained in:
parent
02999925f1
commit
cd836cce9a
2 changed files with 19 additions and 6 deletions
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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 `<T>` in function signature)
|
||||
* @returns undefined if main window webContents is not found
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue