From 08d0fff557e6c6d0c3c091bc4cfe9a982c6b3925 Mon Sep 17 00:00:00 2001 From: Jonas Schwabe Date: Wed, 19 Oct 2016 11:35:32 +0200 Subject: [PATCH 1/2] Remove cache on app update, fixes #342 --- src/common/settings.js | 4 +++- src/main.js | 25 ++++++++++++++++++++++--- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/common/settings.js b/src/common/settings.js index 102182c0..67eaa7c6 100644 --- a/src/common/settings.js +++ b/src/common/settings.js @@ -45,8 +45,10 @@ var upgradeV0toV1 = function(config_v0) { return config; }; -var upgrade = function(config) { +var upgrade = function(config, newAppVersion) { var config_version = config.version ? config.version : 0; + if (newAppVersion) + config.lastMattermostVersion = newAppVersion; switch (config_version) { case 0: return upgrade(upgradeV0toV1(config)); diff --git a/src/main.js b/src/main.js index 66bcba50..82d32f16 100644 --- a/src/main.js +++ b/src/main.js @@ -82,14 +82,15 @@ var config = {}; try { var configFile = global['config-file']; config = settings.readFileSync(configFile); - if (config.version != settings.version) { - config = settings.upgrade(config); + if (config.version != settings.version || wasUpdated()) { + clearAppCache(); + config = settings.upgrade(config, app.getVersion()); settings.writeFileSync(configFile, config); } } catch (e) { config = settings.loadDefault(); - console.log('Failed to read or upgrade config.json'); + console.log('Failed to read or upgrade config.json', e); } ipcMain.on('update-config', () => { config = settings.readFileSync(configFile); @@ -170,6 +171,24 @@ function shouldShowTrayIcon() { return false; } +function wasUpdated() { + return config.lastMattermostVersion != app.getVersion(); +} + +function clearAppCache() { + //Wait for mainWindow + if (!mainWindow) { + setTimeout(clearAppCache, 100); + } + else { + console.log('Clear cache after update'); + mainWindow.webContents.session.clearCache(function() { + //Restart after cache clear + mainWindow.reload(); + }); + } +} + // Quit when all windows are closed. app.on('window-all-closed', function() { // On OS X it is common for applications and their menu bar From a857a63dec4336a340b81d055c4867fc3cca860d Mon Sep 17 00:00:00 2001 From: Jonas Schwabe Date: Wed, 19 Oct 2016 11:38:32 +0200 Subject: [PATCH 2/2] :closed_book: Changelog entry for cache clear on update --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f709c60..93ceab5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ Release date: TBD ### Improvements - "Cannot connect to Mattermost" is now on top of the page + - Clear cache on desktop app update: The application cache will be purged whenever the desktop app version changes #### Windows - Copying a links address and pasting it inside the app now works