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 allowProtocolDialog = require('./main/allowProtocolDialog');
|
||||||
const PermissionManager = require('./main/PermissionManager');
|
const PermissionManager = require('./main/PermissionManager');
|
||||||
const permissionRequestHandler = require('./main/permissionRequestHandler');
|
const permissionRequestHandler = require('./main/permissionRequestHandler');
|
||||||
|
const AppStateManager = require('./main/AppStateManager');
|
||||||
|
|
||||||
const SpellChecker = require('./main/SpellChecker');
|
const SpellChecker = require('./main/SpellChecker');
|
||||||
|
|
||||||
@@ -50,6 +51,7 @@ var mainWindow = null;
|
|||||||
let spellChecker = null;
|
let spellChecker = null;
|
||||||
let deeplinkingUrl = null;
|
let deeplinkingUrl = null;
|
||||||
let scheme = null;
|
let scheme = null;
|
||||||
|
let appState = null;
|
||||||
let permissionManager = null;
|
let permissionManager = null;
|
||||||
|
|
||||||
var argv = require('yargs').parse(process.argv.slice(1));
|
var argv = require('yargs').parse(process.argv.slice(1));
|
||||||
@@ -69,8 +71,7 @@ var config = {};
|
|||||||
try {
|
try {
|
||||||
const configFile = app.getPath('userData') + '/config.json';
|
const configFile = app.getPath('userData') + '/config.json';
|
||||||
config = settings.readFileSync(configFile);
|
config = settings.readFileSync(configFile);
|
||||||
if (config.version !== settings.version || wasUpdated()) {
|
if (config.version !== settings.version) {
|
||||||
clearAppCache();
|
|
||||||
config = settings.upgrade(config);
|
config = settings.upgrade(config);
|
||||||
settings.writeFileSync(configFile, config);
|
settings.writeFileSync(configFile, config);
|
||||||
}
|
}
|
||||||
@@ -189,8 +190,8 @@ function shouldShowTrayIcon() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function wasUpdated() {
|
function wasUpdated(lastAppVersion) {
|
||||||
return config.lastMattermostVersion !== app.getVersion();
|
return lastAppVersion !== app.getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearAppCache() {
|
function clearAppCache() {
|
||||||
@@ -370,6 +371,14 @@ app.on('ready', () => {
|
|||||||
if (global.willAppQuit) {
|
if (global.willAppQuit) {
|
||||||
return;
|
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) {
|
if (global.isDev) {
|
||||||
installExtension.default(installExtension.REACT_DEVELOPER_TOOLS).
|
installExtension.default(installExtension.REACT_DEVELOPER_TOOLS).
|
||||||
then((name) => console.log(`Added Extension: ${name}`)).
|
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