From 509c1a7be0fb0b3390e73e0c88dad01c0d0d9c92 Mon Sep 17 00:00:00 2001 From: Devin Binnie <52460000+devinbinnie@users.noreply.github.com> Date: Mon, 1 May 2023 12:09:52 -0400 Subject: [PATCH] [MM-52380] Fix unhandled rejection when clearing app cache (#2696) * [MM-52380] Fix unhandled rejection when clearing app cache * Make sure the window is loaded first --------- Co-authored-by: Mattermost Build --- src/main/app/initialize.ts | 10 +++++----- src/main/app/utils.ts | 6 +++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/main/app/initialize.ts b/src/main/app/initialize.ts index 1b2c8aab..bda850ae 100644 --- a/src/main/app/initialize.ts +++ b/src/main/app/initialize.ts @@ -345,11 +345,6 @@ async function initializeAfterAppReady() { updateSpellCheckerLocales(); } - if (wasUpdated(AppVersionManager.lastAppVersion)) { - clearAppCache(); - } - AppVersionManager.lastAppVersion = app.getVersion(); - if (typeof Config.canUpgrade === 'undefined') { // windows might not be ready, so we have to wait until it is Config.once('update', () => { @@ -472,6 +467,11 @@ async function initializeAfterAppReady() { callback(urlUtils.isTrustedURL(requestingURL, serverURL)); }); + if (wasUpdated(AppVersionManager.lastAppVersion)) { + clearAppCache(); + } + AppVersionManager.lastAppVersion = app.getVersion(); + handleMainWindowIsShown(); } diff --git a/src/main/app/utils.ts b/src/main/app/utils.ts index 07dcd38d..34569188 100644 --- a/src/main/app/utils.ts +++ b/src/main/app/utils.ts @@ -91,7 +91,11 @@ export function clearAppCache() { // TODO: clear cache on browserviews, not in the renderer. const mainWindow = MainWindow.get(); if (mainWindow) { - mainWindow.webContents.session.clearCache().then(mainWindow.reload); + mainWindow.webContents.session.clearCache(). + then(mainWindow.webContents.reload). + catch((err) => { + log.error('clearAppCache', err); + }); } else { //Wait for mainWindow setTimeout(clearAppCache, 100);