Merge pull request #682 from yuya-oc/purge-caches
Fix cache-purging not working
This commit is contained in:
36
src/common/JsonFileManager.js
Normal file
36
src/common/JsonFileManager.js
Normal file
@@ -0,0 +1,36 @@
|
||||
const fs = require('fs');
|
||||
|
||||
class JsonFileManager {
|
||||
constructor(file) {
|
||||
this.jsonFile = file;
|
||||
try {
|
||||
this.json = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
||||
} catch (err) {
|
||||
this.json = {};
|
||||
}
|
||||
}
|
||||
|
||||
writeToFile() {
|
||||
fs.writeFile(this.jsonFile, JSON.stringify(this.json, null, 2), (err) => {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setJson(json) {
|
||||
this.json = json;
|
||||
this.writeToFile();
|
||||
}
|
||||
|
||||
setValue(key, value) {
|
||||
this.json[key] = value;
|
||||
this.writeToFile();
|
||||
}
|
||||
|
||||
getValue(key) {
|
||||
return this.json[key];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = JsonFileManager;
|
17
src/main.js
17
src/main.js
@@ -39,6 +39,7 @@ const downloadURL = require('./main/downloadURL');
|
||||
const allowProtocolDialog = require('./main/allowProtocolDialog');
|
||||
const PermissionManager = require('./main/PermissionManager');
|
||||
const permissionRequestHandler = require('./main/permissionRequestHandler');
|
||||
const AppStateManager = require('./main/AppStateManager');
|
||||
|
||||
const SpellChecker = require('./main/SpellChecker');
|
||||
|
||||
@@ -50,6 +51,7 @@ var mainWindow = null;
|
||||
let spellChecker = null;
|
||||
let deeplinkingUrl = null;
|
||||
let scheme = null;
|
||||
let appState = null;
|
||||
let permissionManager = null;
|
||||
|
||||
var argv = require('yargs').parse(process.argv.slice(1));
|
||||
@@ -69,8 +71,7 @@ var config = {};
|
||||
try {
|
||||
const configFile = app.getPath('userData') + '/config.json';
|
||||
config = settings.readFileSync(configFile);
|
||||
if (config.version !== settings.version || wasUpdated()) {
|
||||
clearAppCache();
|
||||
if (config.version !== settings.version) {
|
||||
config = settings.upgrade(config);
|
||||
settings.writeFileSync(configFile, config);
|
||||
}
|
||||
@@ -189,8 +190,8 @@ function shouldShowTrayIcon() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function wasUpdated() {
|
||||
return config.lastMattermostVersion !== app.getVersion();
|
||||
function wasUpdated(lastAppVersion) {
|
||||
return lastAppVersion !== app.getVersion();
|
||||
}
|
||||
|
||||
function clearAppCache() {
|
||||
@@ -370,6 +371,14 @@ app.on('ready', () => {
|
||||
if (global.willAppQuit) {
|
||||
return;
|
||||
}
|
||||
|
||||
const appStateJson = path.join(app.getPath('userData'), 'app-state.json');
|
||||
appState = new AppStateManager(appStateJson);
|
||||
if (wasUpdated(appState.lastAppVersion)) {
|
||||
clearAppCache();
|
||||
}
|
||||
appState.lastAppVersion = app.getVersion();
|
||||
|
||||
if (global.isDev) {
|
||||
installExtension.default(installExtension.REACT_DEVELOPER_TOOLS).
|
||||
then((name) => console.log(`Added Extension: ${name}`)).
|
||||
|
13
src/main/AppStateManager.js
Normal file
13
src/main/AppStateManager.js
Normal file
@@ -0,0 +1,13 @@
|
||||
const JsonFileManager = require('../common/JsonFileManager');
|
||||
|
||||
class AppStateManager extends JsonFileManager {
|
||||
set lastAppVersion(version) {
|
||||
this.setValue('lastAppVersion', version);
|
||||
}
|
||||
|
||||
get lastAppVersion() {
|
||||
return this.getValue('lastAppVersion');
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AppStateManager;
|
Reference in New Issue
Block a user