mirror of
https://github.com/tiddly-gittly/TidGi-Desktop.git
synced 2026-01-22 20:41:39 -08:00
refactor: didFailLoadTimes deleted, we retry unlimited, to prevent sometimes it just don't load
This commit is contained in:
parent
ef1c1a0b3a
commit
cc55165f5a
5 changed files with 6 additions and 31 deletions
|
|
@ -199,12 +199,6 @@ export default function Main(): JSX.Element {
|
|||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
||||
}, {} as AsyncReturnType<typeof window.service.workspace.getMetaData>);
|
||||
const requestReload = useCallback(async (): Promise<void> => {
|
||||
const activeWorkspace = await window.service.workspace.getActiveWorkspace();
|
||||
if (activeWorkspace !== undefined) {
|
||||
await window.service.workspace.updateMetaData(activeWorkspace.id, {
|
||||
didFailLoadTimes: 0,
|
||||
});
|
||||
}
|
||||
await window.service.window.reload(window.meta.windowName);
|
||||
}, []);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import i18n from '@services/libs/i18n';
|
||||
|
||||
export class ViewLoadUrlError extends Error {
|
||||
constructor(initialUrl: string, retryTimes?: number, additionalMessage = '') {
|
||||
constructor(initialUrl: string, additionalMessage = '') {
|
||||
super();
|
||||
this.name = i18n.t('Error.ViewLoadUrlError');
|
||||
this.message = `${i18n.t('Error.ViewLoadUrlErrorDescription')} initialUrl: ${initialUrl}, retryTimes: ${retryTimes ?? 'undefined'} ${additionalMessage}`;
|
||||
this.message = `${i18n.t('Error.ViewLoadUrlErrorDescription')} initialUrl: ${initialUrl} ${additionalMessage}`;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -290,7 +290,7 @@ export class View implements IViewService {
|
|||
});
|
||||
/**
|
||||
* Try catch loadUrl, other wise it will throw unhandled promise rejection Error: ERR_CONNECTION_REFUSED (-102) loading 'http://localhost:5212/
|
||||
* We will set `didFailLoadErrorMessage`, and `didFailLoadTimes < LOAD_VIEW_MAX_RETRIES` in `setupViewEventHandlers`, it will set didFailLoadErrorMessage, and we throw actuarial error after that
|
||||
* We will set `didFailLoadErrorMessage`, it will set didFailLoadErrorMessage, and we throw actuarial error after that
|
||||
*/
|
||||
const loadInitialUrlWithCatch = async (): Promise<void> => {
|
||||
try {
|
||||
|
|
@ -300,12 +300,7 @@ export class View implements IViewService {
|
|||
unregisterContextMenu();
|
||||
});
|
||||
} catch (error) {
|
||||
let didFailLoadTimes = 0;
|
||||
try {
|
||||
const workspaceMetaData = await this.workspaceService.getMetaData(workspace.id);
|
||||
didFailLoadTimes = workspaceMetaData.didFailLoadTimes ?? 0;
|
||||
} catch {}
|
||||
logger.error(new ViewLoadUrlError(hostReplacedUrl, didFailLoadTimes, `${(error as Error).message} ${(error as Error).stack ?? ''}`));
|
||||
logger.error(new ViewLoadUrlError(hostReplacedUrl, `${(error as Error).message} ${(error as Error).stack ?? ''}`));
|
||||
}
|
||||
};
|
||||
setupViewEventHandlers(view, browserWindow, {
|
||||
|
|
|
|||
|
|
@ -87,7 +87,6 @@ export default function setupViewEventHandlers(
|
|||
// update isLoading to false when load succeed
|
||||
await workspaceService.updateMetaData(workspace.id, {
|
||||
isLoading: false,
|
||||
didFailLoadTimes: 0,
|
||||
});
|
||||
});
|
||||
// focus on initial load
|
||||
|
|
@ -105,7 +104,6 @@ export default function setupViewEventHandlers(
|
|||
// https://github.com/webcatalog/neutron/blob/3d9e65c255792672c8bc6da025513a5404d98730/main-src/libs/views.js#L397
|
||||
view.webContents.on('did-fail-load', async (_event, errorCode, errorDesc, _validateUrl, isMainFrame) => {
|
||||
const [workspaceObject, workspaceMetaData] = await Promise.all([workspaceService.get(workspace.id), workspaceService.getMetaData(workspace.id)]);
|
||||
const didFailLoadTimes = workspaceMetaData.didFailLoadTimes ?? 0;
|
||||
// this event might be triggered
|
||||
// even after the workspace obj and BrowserView
|
||||
// are destroyed. See https://github.com/atomery/webcatalog/issues/836
|
||||
|
|
@ -114,22 +112,14 @@ export default function setupViewEventHandlers(
|
|||
}
|
||||
if (isMainFrame && errorCode < 0 && errorCode !== -3) {
|
||||
// Fix nodejs wiki start slow on system startup, which cause `-102 ERR_CONNECTION_REFUSED` even if wiki said it is booted, we have to retry several times
|
||||
if (
|
||||
errorCode === -102 &&
|
||||
view.webContents.getURL().length > 0 &&
|
||||
workspaceObject.homeUrl.startsWith('http') &&
|
||||
didFailLoadTimes < LOAD_VIEW_MAX_RETRIES
|
||||
) {
|
||||
if (errorCode === -102 && view.webContents.getURL().length > 0 && workspaceObject.homeUrl.startsWith('http')) {
|
||||
setTimeout(async () => {
|
||||
await workspaceService.updateMetaData(workspace.id, {
|
||||
didFailLoadTimes: didFailLoadTimes + 1,
|
||||
});
|
||||
await loadInitialUrlWithCatch();
|
||||
}, 1000);
|
||||
return;
|
||||
}
|
||||
await workspaceService.updateMetaData(workspace.id, {
|
||||
didFailLoadErrorMessage: `${errorCode} ${errorDesc} , retryTimes: ${didFailLoadTimes}`,
|
||||
didFailLoadErrorMessage: `${errorCode} ${errorDesc}`,
|
||||
});
|
||||
if (workspaceObject.active && browserWindow !== undefined && !browserWindow.isDestroyed()) {
|
||||
// fix https://github.com/atomery/singlebox/issues/228
|
||||
|
|
|
|||
|
|
@ -96,10 +96,6 @@ export interface IWorkspaceMetaData {
|
|||
* Error message if this workspace fails loading
|
||||
*/
|
||||
didFailLoadErrorMessage: string | null | undefined;
|
||||
/**
|
||||
* How many times did we retry failed
|
||||
*/
|
||||
didFailLoadTimes?: number;
|
||||
/**
|
||||
* indicating server or webpage is still loading
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue