diff options
author | 2019-09-17 11:24:36 +0200 | |
---|---|---|
committer | 2019-09-17 11:24:36 +0200 | |
commit | 9d255d9c54dd68b550024931ed0774ff7d1ade24 (patch) | |
tree | c537265b7a5c475d80d7ec86bce1f7aa863f13f8 | |
parent | fix(Spellchecker): Fix disabling spellchecker after app start (diff) | |
download | ferdium-app-9d255d9c54dd68b550024931ed0774ff7d1ade24.tar.gz ferdium-app-9d255d9c54dd68b550024931ed0774ff7d1ade24.tar.zst ferdium-app-9d255d9c54dd68b550024931ed0774ff7d1ade24.zip |
cleanup settings store
-rw-r--r-- | src/stores/SettingsStore.js | 36 |
1 files changed, 3 insertions, 33 deletions
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js index a456195bf..75bb38fe0 100644 --- a/src/stores/SettingsStore.js +++ b/src/stores/SettingsStore.js | |||
@@ -1,12 +1,11 @@ | |||
1 | import { ipcRenderer } from 'electron'; | 1 | import { ipcRenderer } from 'electron'; |
2 | import { | 2 | import { |
3 | action, computed, observable, set, | 3 | action, computed, observable, |
4 | } from 'mobx'; | 4 | } from 'mobx'; |
5 | import localStorage from 'mobx-localstorage'; | 5 | import localStorage from 'mobx-localstorage'; |
6 | 6 | ||
7 | import Store from './lib/Store'; | 7 | import Store from './lib/Store'; |
8 | import Request from './lib/Request'; | 8 | import Request from './lib/Request'; |
9 | import CachedRequest from './lib/CachedRequest'; | ||
10 | import { getLocale } from '../helpers/i18n-helpers'; | 9 | import { getLocale } from '../helpers/i18n-helpers'; |
11 | 10 | ||
12 | import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES } from '../config'; | 11 | import { DEFAULT_APP_SETTINGS, FILE_SYSTEM_SETTINGS_TYPES } from '../config'; |
@@ -15,12 +14,8 @@ import { SPELLCHECKER_LOCALES } from '../i18n/languages'; | |||
15 | const debug = require('debug')('Franz:SettingsStore'); | 14 | const debug = require('debug')('Franz:SettingsStore'); |
16 | 15 | ||
17 | export default class SettingsStore extends Store { | 16 | export default class SettingsStore extends Store { |
18 | @observable appSettingsRequest = new CachedRequest(this.api.local, 'getAppSettings'); | ||
19 | |||
20 | @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings'); | 17 | @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings'); |
21 | 18 | ||
22 | fileSystemSettingsRequests = []; | ||
23 | |||
24 | fileSystemSettingsTypes = FILE_SYSTEM_SETTINGS_TYPES; | 19 | fileSystemSettingsTypes = FILE_SYSTEM_SETTINGS_TYPES; |
25 | 20 | ||
26 | @observable _fileSystemSettingsCache = { | 21 | @observable _fileSystemSettingsCache = { |
@@ -35,14 +30,10 @@ export default class SettingsStore extends Store { | |||
35 | this.actions.settings.update.listen(this._update.bind(this)); | 30 | this.actions.settings.update.listen(this._update.bind(this)); |
36 | this.actions.settings.remove.listen(this._remove.bind(this)); | 31 | this.actions.settings.remove.listen(this._remove.bind(this)); |
37 | 32 | ||
38 | this.fileSystemSettingsTypes.forEach((type) => { | ||
39 | this.fileSystemSettingsRequests[type] = new CachedRequest(this.api.local, 'getAppSettings'); | ||
40 | }); | ||
41 | |||
42 | ipcRenderer.on('appSettings', (event, resp) => { | 33 | ipcRenderer.on('appSettings', (event, resp) => { |
43 | debug('Get appSettings resolves', resp.type, resp.data); | 34 | debug('Get appSettings resolves', resp.type, resp.data); |
44 | 35 | ||
45 | this._fileSystemSettingsCache[resp.type] = resp.data; | 36 | Object.assign(this._fileSystemSettingsCache[resp.type], resp.data); |
46 | }); | 37 | }); |
47 | 38 | ||
48 | this.fileSystemSettingsTypes.forEach((type) => { | 39 | this.fileSystemSettingsTypes.forEach((type) => { |
@@ -51,8 +42,6 @@ export default class SettingsStore extends Store { | |||
51 | } | 42 | } |
52 | 43 | ||
53 | async setup() { | 44 | async setup() { |
54 | // We need to wait until `appSettingsRequest` has been executed once, otherwise we can't patch the result. If we don't wait we'd run into an issue with mobx not reacting to changes of previously not existing keys | ||
55 | await this.appSettingsRequest._promise; | ||
56 | await this._migrate(); | 45 | await this._migrate(); |
57 | } | 46 | } |
58 | 47 | ||
@@ -61,21 +50,6 @@ export default class SettingsStore extends Store { | |||
61 | } | 50 | } |
62 | 51 | ||
63 | @computed get proxy() { | 52 | @computed get proxy() { |
64 | // // We need to provide the final data structure as mobx autoruns won't work | ||
65 | // const proxySettings = observable({}); | ||
66 | // this.stores.services.all.forEach((service) => { | ||
67 | // proxySettings[service.id] = { | ||
68 | // isEnabled: false, | ||
69 | // host: null, | ||
70 | // user: null, | ||
71 | // password: null, | ||
72 | // }; | ||
73 | // }); | ||
74 | |||
75 | // debug('this._fileSystemSettingsCache.proxy', this._fileSystemSettingsCache.proxy, proxySettings); | ||
76 | |||
77 | // return Object.assign(proxySettings, this._fileSystemSettingsCache.proxy); | ||
78 | |||
79 | return this._fileSystemSettingsCache.proxy || {}; | 53 | return this._fileSystemSettingsCache.proxy || {}; |
80 | } | 54 | } |
81 | 55 | ||
@@ -117,7 +91,7 @@ export default class SettingsStore extends Store { | |||
117 | data, | 91 | data, |
118 | }); | 92 | }); |
119 | 93 | ||
120 | set(this._fileSystemSettingsCache[type], data); | 94 | Object.assign(this._fileSystemSettingsCache[type], data); |
121 | } | 95 | } |
122 | } | 96 | } |
123 | 97 | ||
@@ -197,8 +171,4 @@ export default class SettingsStore extends Store { | |||
197 | }); | 171 | }); |
198 | } | 172 | } |
199 | } | 173 | } |
200 | |||
201 | _getFileBasedSettings(type) { | ||
202 | ipcRenderer.send('getAppSettings', type); | ||
203 | } | ||
204 | } | 174 | } |