diff options
author | 2017-12-29 01:33:42 -0500 | |
---|---|---|
committer | 2017-12-29 01:33:46 -0500 | |
commit | 33c6e0af4112a927027a2533dea4bea3750e7865 (patch) | |
tree | fabd8a62049a187c70063e14d5171fa65dc1d159 | |
parent | Delete session partition with service (diff) | |
download | ferdium-app-33c6e0af4112a927027a2533dea4bea3750e7865.tar.gz ferdium-app-33c6e0af4112a927027a2533dea4bea3750e7865.tar.zst ferdium-app-33c6e0af4112a927027a2533dea4bea3750e7865.zip |
Add button to clear global cache and all services
-rw-r--r-- | src/actions/app.js | 1 | ||||
-rw-r--r-- | src/api/server/LocalApi.js | 5 | ||||
-rw-r--r-- | src/components/settings/settings/EditSettingsForm.js | 30 | ||||
-rw-r--r-- | src/containers/settings/EditSettingsScreen.js | 7 | ||||
-rw-r--r-- | src/i18n/locales/en-US.json | 2 | ||||
-rw-r--r-- | src/stores/AppStore.js | 15 |
6 files changed, 58 insertions, 2 deletions
diff --git a/src/actions/app.js b/src/actions/app.js index e4f648fc9..e6f7f22ba 100644 --- a/src/actions/app.js +++ b/src/actions/app.js | |||
@@ -25,4 +25,5 @@ export default { | |||
25 | overrideSystemMute: PropTypes.bool, | 25 | overrideSystemMute: PropTypes.bool, |
26 | }, | 26 | }, |
27 | toggleMuteApp: {}, | 27 | toggleMuteApp: {}, |
28 | clearAllCache: {}, | ||
28 | }; | 29 | }; |
diff --git a/src/api/server/LocalApi.js b/src/api/server/LocalApi.js index fec89f948..d2ce0c9de 100644 --- a/src/api/server/LocalApi.js +++ b/src/api/server/LocalApi.js | |||
@@ -41,4 +41,9 @@ export default class LocalApi { | |||
41 | const s = session.fromPartition(`persist:service-${serviceId}`); | 41 | const s = session.fromPartition(`persist:service-${serviceId}`); |
42 | await new Promise(resolve => s.clearCache(resolve)); | 42 | await new Promise(resolve => s.clearCache(resolve)); |
43 | } | 43 | } |
44 | |||
45 | async clearAppCache() { | ||
46 | const s = session.defaultSession; | ||
47 | await new Promise(resolve => s.clearCache(resolve)); | ||
48 | } | ||
44 | } | 49 | } |
diff --git a/src/components/settings/settings/EditSettingsForm.js b/src/components/settings/settings/EditSettingsForm.js index ff398aa33..074a4b731 100644 --- a/src/components/settings/settings/EditSettingsForm.js +++ b/src/components/settings/settings/EditSettingsForm.js | |||
@@ -40,6 +40,14 @@ const messages = defineMessages({ | |||
40 | id: 'settings.app.translationHelp', | 40 | id: 'settings.app.translationHelp', |
41 | defaultMessage: '!!!Help us to translate Franz into your language.', | 41 | defaultMessage: '!!!Help us to translate Franz into your language.', |
42 | }, | 42 | }, |
43 | buttonClearAllCache: { | ||
44 | id: 'settings.app.buttonClearAllCache', | ||
45 | defaultMessage: '!!!Clear global cache for Franz and all services', | ||
46 | }, | ||
47 | buttonClearingAllCache: { | ||
48 | id: 'settings.app.buttonClearingAllCache', | ||
49 | defaultMessage: '!!!Clearing global cache...', | ||
50 | }, | ||
43 | buttonSearchForUpdate: { | 51 | buttonSearchForUpdate: { |
44 | id: 'settings.app.buttonSearchForUpdate', | 52 | id: 'settings.app.buttonSearchForUpdate', |
45 | defaultMessage: '!!!Check for updates', | 53 | defaultMessage: '!!!Check for updates', |
@@ -77,6 +85,8 @@ export default class EditSettingsForm extends Component { | |||
77 | isUpdateAvailable: PropTypes.bool.isRequired, | 85 | isUpdateAvailable: PropTypes.bool.isRequired, |
78 | noUpdateAvailable: PropTypes.bool.isRequired, | 86 | noUpdateAvailable: PropTypes.bool.isRequired, |
79 | updateIsReadyToInstall: PropTypes.bool.isRequired, | 87 | updateIsReadyToInstall: PropTypes.bool.isRequired, |
88 | isClearingAllCache: PropTypes.bool.isRequired, | ||
89 | onClearAllCache: PropTypes.func.isRequired, | ||
80 | }; | 90 | }; |
81 | 91 | ||
82 | static contextTypes = { | 92 | static contextTypes = { |
@@ -103,6 +113,8 @@ export default class EditSettingsForm extends Component { | |||
103 | isUpdateAvailable, | 113 | isUpdateAvailable, |
104 | noUpdateAvailable, | 114 | noUpdateAvailable, |
105 | updateIsReadyToInstall, | 115 | updateIsReadyToInstall, |
116 | isClearingAllCache, | ||
117 | onClearAllCache, | ||
106 | } = this.props; | 118 | } = this.props; |
107 | const { intl } = this.context; | 119 | const { intl } = this.context; |
108 | 120 | ||
@@ -115,6 +127,23 @@ export default class EditSettingsForm extends Component { | |||
115 | updateButtonLabelMessage = messages.buttonSearchForUpdate; | 127 | updateButtonLabelMessage = messages.buttonSearchForUpdate; |
116 | } | 128 | } |
117 | 129 | ||
130 | const clearAllCacheButton = isClearingAllCache ? ( | ||
131 | <Button | ||
132 | buttonType="secondary" | ||
133 | className="settings__clear-all-cache-button" | ||
134 | loaded={false} | ||
135 | label={intl.formatMessage(messages.buttonClearingAllCache)} | ||
136 | disabled | ||
137 | /> | ||
138 | ) : ( | ||
139 | <Button | ||
140 | buttonType="warning" | ||
141 | className="settings__clear-all-cache-button" | ||
142 | label={intl.formatMessage(messages.buttonClearAllCache)} | ||
143 | onClick={onClearAllCache} | ||
144 | /> | ||
145 | ); | ||
146 | |||
118 | return ( | 147 | return ( |
119 | <div className="settings__main"> | 148 | <div className="settings__main"> |
120 | <div className="settings__header"> | 149 | <div className="settings__header"> |
@@ -155,6 +184,7 @@ export default class EditSettingsForm extends Component { | |||
155 | <h2 id="advanced">{intl.formatMessage(messages.headlineAdvanced)}</h2> | 184 | <h2 id="advanced">{intl.formatMessage(messages.headlineAdvanced)}</h2> |
156 | <Toggle field={form.$('enableSpellchecking')} /> | 185 | <Toggle field={form.$('enableSpellchecking')} /> |
157 | {/* <Select field={form.$('spellcheckingLanguage')} /> */} | 186 | {/* <Select field={form.$('spellcheckingLanguage')} /> */} |
187 | {clearAllCacheButton} | ||
158 | 188 | ||
159 | {/* Updates */} | 189 | {/* Updates */} |
160 | <h2 id="updates">{intl.formatMessage(messages.headlineUpdates)}</h2> | 190 | <h2 id="updates">{intl.formatMessage(messages.headlineUpdates)}</h2> |
diff --git a/src/containers/settings/EditSettingsScreen.js b/src/containers/settings/EditSettingsScreen.js index 45ded9e5c..890bf6501 100644 --- a/src/containers/settings/EditSettingsScreen.js +++ b/src/containers/settings/EditSettingsScreen.js | |||
@@ -193,8 +193,8 @@ export default class EditSettingsScreen extends Component { | |||
193 | } | 193 | } |
194 | 194 | ||
195 | render() { | 195 | render() { |
196 | const { updateStatus, updateStatusTypes } = this.props.stores.app; | 196 | const { updateStatus, updateStatusTypes, isClearingAllCache } = this.props.stores.app; |
197 | const { checkForUpdates, installUpdate } = this.props.actions.app; | 197 | const { checkForUpdates, installUpdate, clearAllCache } = this.props.actions.app; |
198 | const form = this.prepareForm(); | 198 | const form = this.prepareForm(); |
199 | 199 | ||
200 | return ( | 200 | return ( |
@@ -207,6 +207,8 @@ export default class EditSettingsScreen extends Component { | |||
207 | noUpdateAvailable={updateStatus === updateStatusTypes.NOT_AVAILABLE} | 207 | noUpdateAvailable={updateStatus === updateStatusTypes.NOT_AVAILABLE} |
208 | updateIsReadyToInstall={updateStatus === updateStatusTypes.DOWNLOADED} | 208 | updateIsReadyToInstall={updateStatus === updateStatusTypes.DOWNLOADED} |
209 | onSubmit={d => this.onSubmit(d)} | 209 | onSubmit={d => this.onSubmit(d)} |
210 | isClearingAllCache={isClearingAllCache} | ||
211 | onClearAllCache={clearAllCache} | ||
210 | /> | 212 | /> |
211 | ); | 213 | ); |
212 | } | 214 | } |
@@ -223,6 +225,7 @@ EditSettingsScreen.wrappedComponent.propTypes = { | |||
223 | launchOnStartup: PropTypes.func.isRequired, | 225 | launchOnStartup: PropTypes.func.isRequired, |
224 | checkForUpdates: PropTypes.func.isRequired, | 226 | checkForUpdates: PropTypes.func.isRequired, |
225 | installUpdate: PropTypes.func.isRequired, | 227 | installUpdate: PropTypes.func.isRequired, |
228 | clearAllCache: PropTypes.func.isRequired, | ||
226 | }).isRequired, | 229 | }).isRequired, |
227 | settings: PropTypes.shape({ | 230 | settings: PropTypes.shape({ |
228 | update: PropTypes.func.isRequired, | 231 | update: PropTypes.func.isRequired, |
diff --git a/src/i18n/locales/en-US.json b/src/i18n/locales/en-US.json index 2b5a3fc4b..665d0e3cd 100644 --- a/src/i18n/locales/en-US.json +++ b/src/i18n/locales/en-US.json | |||
@@ -151,6 +151,8 @@ | |||
151 | "settings.app.updateStatusSearching": "Is searching for update", | 151 | "settings.app.updateStatusSearching": "Is searching for update", |
152 | "settings.app.updateStatusAvailable": "Update available, downloading...", | 152 | "settings.app.updateStatusAvailable": "Update available, downloading...", |
153 | "settings.app.updateStatusUpToDate": "You are using the latest version of Franz", | 153 | "settings.app.updateStatusUpToDate": "You are using the latest version of Franz", |
154 | "settings.app.buttonClearAllCache": "Clear global cache for Franz and all services", | ||
155 | "settings.app.buttonClearingAllCache": "Clearing global cache...", | ||
154 | "settings.app.form.autoLaunchOnStart": "Launch Franz on start", | 156 | "settings.app.form.autoLaunchOnStart": "Launch Franz on start", |
155 | "settings.app.form.autoLaunchInBackground": "Open in background", | 157 | "settings.app.form.autoLaunchInBackground": "Open in background", |
156 | "settings.app.form.enableSystemTray": "Show Franz in system tray", | 158 | "settings.app.form.enableSystemTray": "Show Franz in system tray", |
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 5a6c12ee1..1136629ba 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js | |||
@@ -14,6 +14,8 @@ import locales from '../i18n/translations'; | |||
14 | import { gaEvent } from '../lib/analytics'; | 14 | import { gaEvent } from '../lib/analytics'; |
15 | import Miner from '../lib/Miner'; | 15 | import Miner from '../lib/Miner'; |
16 | 16 | ||
17 | import { getServiceIdsFromPartitions } from '../helpers/service-helpers.js'; | ||
18 | |||
17 | const { app, powerMonitor } = remote; | 19 | const { app, powerMonitor } = remote; |
18 | const defaultLocale = DEFAULT_APP_SETTINGS.locale; | 20 | const defaultLocale = DEFAULT_APP_SETTINGS.locale; |
19 | const autoLauncher = new AutoLaunch({ | 21 | const autoLauncher = new AutoLaunch({ |
@@ -30,6 +32,7 @@ export default class AppStore extends Store { | |||
30 | }; | 32 | }; |
31 | 33 | ||
32 | @observable healthCheckRequest = new Request(this.api.app, 'health'); | 34 | @observable healthCheckRequest = new Request(this.api.app, 'health'); |
35 | @observable clearAppCacheRequest = new Request(this.api.local, 'clearAppCache'); | ||
33 | 36 | ||
34 | @observable autoLaunchOnStart = true; | 37 | @observable autoLaunchOnStart = true; |
35 | 38 | ||
@@ -47,6 +50,8 @@ export default class AppStore extends Store { | |||
47 | 50 | ||
48 | @observable isSystemMuteOverridden = false; | 51 | @observable isSystemMuteOverridden = false; |
49 | 52 | ||
53 | @observable isClearingAllCache = false; | ||
54 | |||
50 | constructor(...args) { | 55 | constructor(...args) { |
51 | super(...args); | 56 | super(...args); |
52 | 57 | ||
@@ -61,6 +66,7 @@ export default class AppStore extends Store { | |||
61 | this.actions.app.healthCheck.listen(this._healthCheck.bind(this)); | 66 | this.actions.app.healthCheck.listen(this._healthCheck.bind(this)); |
62 | this.actions.app.muteApp.listen(this._muteApp.bind(this)); | 67 | this.actions.app.muteApp.listen(this._muteApp.bind(this)); |
63 | this.actions.app.toggleMuteApp.listen(this._toggleMuteApp.bind(this)); | 68 | this.actions.app.toggleMuteApp.listen(this._toggleMuteApp.bind(this)); |
69 | this.actions.app.clearAllCache.listen(this._clearAllCache.bind(this)); | ||
64 | 70 | ||
65 | this.registerReactions([ | 71 | this.registerReactions([ |
66 | this._offlineCheck.bind(this), | 72 | this._offlineCheck.bind(this), |
@@ -247,6 +253,15 @@ export default class AppStore extends Store { | |||
247 | this._muteApp({ isMuted: !this.stores.settings.all.isAppMuted }); | 253 | this._muteApp({ isMuted: !this.stores.settings.all.isAppMuted }); |
248 | } | 254 | } |
249 | 255 | ||
256 | @action async _clearAllCache() { | ||
257 | this.isClearingAllCache = true; | ||
258 | const clearAppCache = this.clearAppCacheRequest.execute(); | ||
259 | const serviceIds = await getServiceIdsFromPartitions(); | ||
260 | await Promise.all(serviceIds.map(id => this.actions.service.clearCache({ serviceId: id, }))); | ||
261 | await clearAppCache._promise; | ||
262 | this.isClearingAllCache = false; | ||
263 | } | ||
264 | |||
250 | // Reactions | 265 | // Reactions |
251 | _offlineCheck() { | 266 | _offlineCheck() { |
252 | if (!this.isOnline) { | 267 | if (!this.isOnline) { |