Merge pull request #345 from jnugh/updateCacheClear
Purge cache on app update
This commit is contained in:
commit
9a0c3f4075
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
|
|
25
src/main.js
25
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
|
||||
|
|
Loading…
Reference in a new issue