aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/AppStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/AppStore.js')
-rw-r--r--src/stores/AppStore.js22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js
index ac8d15632..63130a3ba 100644
--- a/src/stores/AppStore.js
+++ b/src/stores/AppStore.js
@@ -1,10 +1,11 @@
1import { remote, ipcRenderer, shell } from 'electron'; 1import { remote, ipcRenderer, shell } from 'electron';
2import { action, observable } from 'mobx'; 2import { action, computed, observable } from 'mobx';
3import moment from 'moment'; 3import moment from 'moment';
4import key from 'keymaster'; 4import key from 'keymaster';
5import { getDoNotDisturb } from '@meetfranz/electron-notification-state'; 5import { getDoNotDisturb } from '@meetfranz/electron-notification-state';
6import idleTimer from '@paulcbetts/system-idle-time'; 6import idleTimer from '@paulcbetts/system-idle-time';
7import AutoLaunch from 'auto-launch'; 7import AutoLaunch from 'auto-launch';
8import prettyBytes from 'pretty-bytes';
8 9
9import Store from './lib/Store'; 10import Store from './lib/Store';
10import Request from './lib/Request'; 11import Request from './lib/Request';
@@ -14,7 +15,7 @@ import locales from '../i18n/translations';
14import { gaEvent } from '../lib/analytics'; 15import { gaEvent } from '../lib/analytics';
15import Miner from '../lib/Miner'; 16import Miner from '../lib/Miner';
16 17
17import { getServiceIdsFromPartitions } from '../helpers/service-helpers.js'; 18import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js';
18 19
19const { app, powerMonitor } = remote; 20const { app, powerMonitor } = remote;
20const defaultLocale = DEFAULT_APP_SETTINGS.locale; 21const defaultLocale = DEFAULT_APP_SETTINGS.locale;
@@ -32,6 +33,7 @@ export default class AppStore extends Store {
32 }; 33 };
33 34
34 @observable healthCheckRequest = new Request(this.api.app, 'health'); 35 @observable healthCheckRequest = new Request(this.api.app, 'health');
36 @observable getAppCacheSizeRequest = new Request(this.api.local, 'getAppCacheSize');
35 @observable clearAppCacheRequest = new Request(this.api.local, 'clearAppCache'); 37 @observable clearAppCacheRequest = new Request(this.api.local, 'clearAppCache');
36 38
37 @observable autoLaunchOnStart = true; 39 @observable autoLaunchOnStart = true;
@@ -163,6 +165,10 @@ export default class AppStore extends Store {
163 this._healthCheck(); 165 this._healthCheck();
164 } 166 }
165 167
168 @computed get cacheSize() {
169 return prettyBytes(this.getAppCacheSizeRequest.execute().result || 0);
170 }
171
166 // Actions 172 // Actions
167 @action _notify({ title, options, notificationId, serviceId = null }) { 173 @action _notify({ title, options, notificationId, serviceId = null }) {
168 if (this.stores.settings.all.isAppMuted) return; 174 if (this.stores.settings.all.isAppMuted) return;
@@ -256,9 +262,17 @@ export default class AppStore extends Store {
256 @action async _clearAllCache() { 262 @action async _clearAllCache() {
257 this.isClearingAllCache = true; 263 this.isClearingAllCache = true;
258 const clearAppCache = this.clearAppCacheRequest.execute(); 264 const clearAppCache = this.clearAppCacheRequest.execute();
259 const serviceIds = await getServiceIdsFromPartitions(); 265 const allServiceIds = await getServiceIdsFromPartitions();
260 await Promise.all(serviceIds.map(id => this.actions.service.clearCache({ serviceId: id }))); 266 const allOrphanedServiceIds = allServiceIds.filter(id => !this.stores.services.all.find(s => id.replace('service-', '') === s.id));
267
268 await Promise.all(allOrphanedServiceIds.map(id => removeServicePartitionDirectory(id)));
269
270 await Promise.all(this.stores.services.all.map(s => this.actions.service.clearCache({ serviceId: s.id })));
271
261 await clearAppCache._promise; 272 await clearAppCache._promise;
273
274 this.getAppCacheSizeRequest.execute();
275
262 this.isClearingAllCache = false; 276 this.isClearingAllCache = false;
263 } 277 }
264 278