Merge pull request #345 from jnugh/updateCacheClear

Purge cache on app update
This commit is contained in:
Yuya Ochiai
2016-10-27 20:55:36 +09:00
3 changed files with 26 additions and 4 deletions

View File

@@ -11,6 +11,7 @@ Release date: TBD
### Improvements ### Improvements
- "Cannot connect to Mattermost" is now on top of the page - "Cannot connect to Mattermost" is now on top of the page
- Suppressed verbose error which is related to certificates - Suppressed verbose error which is related to certificates
- Clear cache on desktop app update: The application cache will be purged whenever the desktop app version changes
#### Windows #### Windows
- Copying a links address and pasting it inside the app now works - Copying a links address and pasting it inside the app now works

View File

@@ -45,8 +45,10 @@ var upgradeV0toV1 = function(config_v0) {
return config; return config;
}; };
var upgrade = function(config) { var upgrade = function(config, newAppVersion) {
var config_version = config.version ? config.version : 0; var config_version = config.version ? config.version : 0;
if (newAppVersion)
config.lastMattermostVersion = newAppVersion;
switch (config_version) { switch (config_version) {
case 0: case 0:
return upgrade(upgradeV0toV1(config)); return upgrade(upgradeV0toV1(config));

View File

@@ -82,14 +82,15 @@ var config = {};
try { try {
var configFile = global['config-file']; var configFile = global['config-file'];
config = settings.readFileSync(configFile); config = settings.readFileSync(configFile);
if (config.version != settings.version) { if (config.version != settings.version || wasUpdated()) {
config = settings.upgrade(config); clearAppCache();
config = settings.upgrade(config, app.getVersion());
settings.writeFileSync(configFile, config); settings.writeFileSync(configFile, config);
} }
} }
catch (e) { catch (e) {
config = settings.loadDefault(); 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', () => { ipcMain.on('update-config', () => {
config = settings.readFileSync(configFile); config = settings.readFileSync(configFile);
@@ -170,6 +171,24 @@ function shouldShowTrayIcon() {
return false; 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. // Quit when all windows are closed.
app.on('window-all-closed', function() { app.on('window-all-closed', function() {
// On OS X it is common for applications and their menu bar // On OS X it is common for applications and their menu bar