diff options
-rw-r--r-- | src/api/server/LocalApi.js | 32 | ||||
-rw-r--r-- | src/stores/AppStore.js | 9 | ||||
-rw-r--r-- | src/stores/SettingsStore.js | 21 | ||||
-rw-r--r-- | src/stores/UserStore.js | 1 |
4 files changed, 12 insertions, 51 deletions
diff --git a/src/api/server/LocalApi.js b/src/api/server/LocalApi.js index efbb42999..1988f713c 100644 --- a/src/api/server/LocalApi.js +++ b/src/api/server/LocalApi.js | |||
@@ -7,38 +7,6 @@ import { getServicePartitionsDirectory } from '../../helpers/service-helpers.js' | |||
7 | const { session } = remote; | 7 | const { session } = remote; |
8 | 8 | ||
9 | export default class LocalApi { | 9 | export default class LocalApi { |
10 | // App | ||
11 | async updateAppSettings(data) { | ||
12 | const currentSettings = await this.getAppSettings(); | ||
13 | const settings = Object.assign(currentSettings, data); | ||
14 | |||
15 | localStorage.setItem('app', JSON.stringify(settings)); | ||
16 | console.debug('LocalApi::updateAppSettings resolves', settings); | ||
17 | |||
18 | return settings; | ||
19 | } | ||
20 | |||
21 | async getAppSettings() { | ||
22 | const settingsString = localStorage.getItem('app'); | ||
23 | try { | ||
24 | const settings = JSON.parse(settingsString) || {}; | ||
25 | console.debug('LocalApi::getAppSettings resolves', settings); | ||
26 | |||
27 | return settings; | ||
28 | } catch (err) { | ||
29 | return {}; | ||
30 | } | ||
31 | } | ||
32 | |||
33 | async removeKey(key) { | ||
34 | const settings = await this.getAppSettings(); | ||
35 | |||
36 | if (Object.hasOwnProperty.call(settings, key)) { | ||
37 | delete settings[key]; | ||
38 | localStorage.setItem('app', JSON.stringify(settings)); | ||
39 | } | ||
40 | } | ||
41 | |||
42 | // Services | 10 | // Services |
43 | async getAppCacheSize() { | 11 | async getAppCacheSize() { |
44 | const partitionsDir = getServicePartitionsDirectory(); | 12 | const partitionsDir = getServicePartitionsDirectory(); |
diff --git a/src/stores/AppStore.js b/src/stores/AppStore.js index 06c43f83f..77027f88d 100644 --- a/src/stores/AppStore.js +++ b/src/stores/AppStore.js | |||
@@ -331,10 +331,7 @@ export default class AppStore extends Store { | |||
331 | } | 331 | } |
332 | 332 | ||
333 | // Helpers | 333 | // Helpers |
334 | async _appStartsCounter() { | 334 | _appStartsCounter() { |
335 | // we need to wait until the settings request is resolved | ||
336 | await this.stores.settings.allSettingsRequest; | ||
337 | |||
338 | this.actions.settings.update({ | 335 | this.actions.settings.update({ |
339 | settings: { | 336 | settings: { |
340 | appStarts: (this.stores.settings.all.appStarts || 0) + 1, | 337 | appStarts: (this.stores.settings.all.appStarts || 0) + 1, |
@@ -345,10 +342,10 @@ export default class AppStore extends Store { | |||
345 | async _autoStart() { | 342 | async _autoStart() { |
346 | this.autoLaunchOnStart = await this._checkAutoStart(); | 343 | this.autoLaunchOnStart = await this._checkAutoStart(); |
347 | 344 | ||
348 | // we need to wait until the settings request is resolved | 345 | console.log('### settings appstarts', this.stores.settings.all.appStarts); |
349 | await this.stores.settings.allSettingsRequest; | ||
350 | 346 | ||
351 | if (!this.stores.settings.all.appStarts) { | 347 | if (!this.stores.settings.all.appStarts) { |
348 | console.log('launch Franz on start'); | ||
352 | this.actions.app.launchOnStartup({ | 349 | this.actions.app.launchOnStartup({ |
353 | enable: true, | 350 | enable: true, |
354 | }); | 351 | }); |
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index 26d895b7e..f6f340c2b 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js | |||
@@ -1,5 +1,6 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import { action, computed, observable, extendObservable } from 'mobx'; | 2 | import { action, computed, observable, extendObservable } from 'mobx'; |
3 | import localStorage from 'mobx-localstorage'; | ||
3 | 4 | ||
4 | import Store from './lib/Store'; | 5 | import Store from './lib/Store'; |
5 | import Request from './lib/Request'; | 6 | import Request from './lib/Request'; |
@@ -26,19 +27,12 @@ export default class SettingsStore extends Store { | |||
26 | } | 27 | } |
27 | 28 | ||
28 | @computed get all() { | 29 | @computed get all() { |
29 | console.log('get all settings'); | 30 | return new SettingsModel(localStorage.getItem('app') || {}); |
30 | return new SettingsModel(this.allSettingsRequest.result); | ||
31 | } | 31 | } |
32 | 32 | ||
33 | @action async _update({ settings }) { | 33 | @action async _update({ settings }) { |
34 | await this.updateSettingsRequest.execute(settings)._promise; | 34 | const appSettings = this.all; |
35 | // await this.allSettingsRequest.patch((result) => { | 35 | localStorage.setItem('app', Object.assign(appSettings, settings)); |
36 | // if (!result) return; | ||
37 | // console.log(result.runInBackground, settings.runInBackground); | ||
38 | // extendObservable(result, settings); | ||
39 | // console.log(result.runInBackground); | ||
40 | // // result.update(settings); | ||
41 | // }); | ||
42 | 36 | ||
43 | // We need a little hack to wait until everything is patched | 37 | // We need a little hack to wait until everything is patched |
44 | setTimeout(() => this._shareSettingsWithMainProcess(), 0); | 38 | setTimeout(() => this._shareSettingsWithMainProcess(), 0); |
@@ -47,8 +41,11 @@ export default class SettingsStore extends Store { | |||
47 | } | 41 | } |
48 | 42 | ||
49 | @action async _remove({ key }) { | 43 | @action async _remove({ key }) { |
50 | await this.removeSettingsKeyRequest.execute(key); | 44 | const appSettings = this.all; |
51 | await this.allSettingsRequest.invalidate({ immediately: true }); | 45 | if (Object.hasOwnProperty.call(appSettings, key)) { |
46 | delete appSettings[key]; | ||
47 | localStorage.setItem('app', appSettings); | ||
48 | } | ||
52 | 49 | ||
53 | this._shareSettingsWithMainProcess(); | 50 | this._shareSettingsWithMainProcess(); |
54 | } | 51 | } |
diff --git a/src/stores/UserStore.js b/src/stores/UserStore.js index 7b8ffb2b2..7dbbd955b 100644 --- a/src/stores/UserStore.js +++ b/src/stores/UserStore.js | |||
@@ -226,7 +226,6 @@ export default class UserStore extends Store { | |||
226 | 226 | ||
227 | // This is a mobx autorun which forces the user to login if not authenticated | 227 | // This is a mobx autorun which forces the user to login if not authenticated |
228 | _requireAuthenticatedUser = () => { | 228 | _requireAuthenticatedUser = () => { |
229 | console.log('requireAuthenticatedUser'); | ||
230 | if (this.isTokenExpired) { | 229 | if (this.isTokenExpired) { |
231 | this._logout(); | 230 | this._logout(); |
232 | } | 231 | } |