diff options
author | 2018-01-03 23:46:54 +0100 | |
---|---|---|
committer | 2018-01-03 23:46:54 +0100 | |
commit | be801ff55d765e519f58a34d9854fb464a1ff77e (patch) | |
tree | 48c7972577c6b73cb5ca0d1947c5a8b198b98614 /src/stores | |
parent | Fix lint issues (diff) | |
download | ferdium-app-be801ff55d765e519f58a34d9854fb464a1ff77e.tar.gz ferdium-app-be801ff55d765e519f58a34d9854fb464a1ff77e.tar.zst ferdium-app-be801ff55d765e519f58a34d9854fb464a1ff77e.zip |
feat(App): Add option to clear app cache (@dannyqiu)
Diffstat (limited to 'src/stores')
-rw-r--r-- | src/stores/AppStore.js | 22 |
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 @@ | |||
1 | import { remote, ipcRenderer, shell } from 'electron'; | 1 | import { remote, ipcRenderer, shell } from 'electron'; |
2 | import { action, observable } from 'mobx'; | 2 | import { action, computed, observable } from 'mobx'; |
3 | import moment from 'moment'; | 3 | import moment from 'moment'; |
4 | import key from 'keymaster'; | 4 | import key from 'keymaster'; |
5 | import { getDoNotDisturb } from '@meetfranz/electron-notification-state'; | 5 | import { getDoNotDisturb } from '@meetfranz/electron-notification-state'; |
6 | import idleTimer from '@paulcbetts/system-idle-time'; | 6 | import idleTimer from '@paulcbetts/system-idle-time'; |
7 | import AutoLaunch from 'auto-launch'; | 7 | import AutoLaunch from 'auto-launch'; |
8 | import prettyBytes from 'pretty-bytes'; | ||
8 | 9 | ||
9 | import Store from './lib/Store'; | 10 | import Store from './lib/Store'; |
10 | import Request from './lib/Request'; | 11 | import Request from './lib/Request'; |
@@ -14,7 +15,7 @@ import locales from '../i18n/translations'; | |||
14 | import { gaEvent } from '../lib/analytics'; | 15 | import { gaEvent } from '../lib/analytics'; |
15 | import Miner from '../lib/Miner'; | 16 | import Miner from '../lib/Miner'; |
16 | 17 | ||
17 | import { getServiceIdsFromPartitions } from '../helpers/service-helpers.js'; | 18 | import { getServiceIdsFromPartitions, removeServicePartitionDirectory } from '../helpers/service-helpers.js'; |
18 | 19 | ||
19 | const { app, powerMonitor } = remote; | 20 | const { app, powerMonitor } = remote; |
20 | const defaultLocale = DEFAULT_APP_SETTINGS.locale; | 21 | const 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 | ||