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
commit 9a0c3f4075
3 changed files with 26 additions and 4 deletions

View file

@ -11,6 +11,7 @@ Release date: TBD
### Improvements
- "Cannot connect to Mattermost" is now on top of the page
- 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
- 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;
};
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));

View file

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