[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 <build@mattermost.com>
This commit is contained in:
Devin Binnie
2023-05-01 12:09:52 -04:00
committed by GitHub
parent 35e2b81677
commit 509c1a7be0
2 changed files with 10 additions and 6 deletions

View File

@@ -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();
}

View File

@@ -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);