Remove cache on app update, fixes #342
This commit is contained in:
@@ -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));
|
||||||
|
25
src/main.js
25
src/main.js
@@ -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
|
||||||
|
Reference in New Issue
Block a user