aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/SettingsStore.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/stores/SettingsStore.js')
-rw-r--r--src/stores/SettingsStore.js36
1 files changed, 3 insertions, 33 deletions
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js
index f6a53f147..c09f24af7 100644
--- a/src/stores/SettingsStore.js
+++ b/src/stores/SettingsStore.js
@@ -1,12 +1,11 @@
1import { ipcRenderer, remote } from 'electron'; 1import { ipcRenderer, remote } from 'electron';
2import { 2import {
3 action, computed, observable, set, reaction, 3 action, computed, observable, reaction,
4} from 'mobx'; 4} from 'mobx';
5import localStorage from 'mobx-localstorage'; 5import localStorage from 'mobx-localstorage';
6 6
7import Store from './lib/Store'; 7import Store from './lib/Store';
8import Request from './lib/Request'; 8import Request from './lib/Request';
9import CachedRequest from './lib/CachedRequest';
10import { getLocale } from '../helpers/i18n-helpers'; 9import { getLocale } from '../helpers/i18n-helpers';
11import { API } from '../environment'; 10import { API } from '../environment';
12 11
@@ -16,12 +15,8 @@ import { SPELLCHECKER_LOCALES } from '../i18n/languages';
16const debug = require('debug')('Ferdi:SettingsStore'); 15const debug = require('debug')('Ferdi:SettingsStore');
17 16
18export default class SettingsStore extends Store { 17export default class SettingsStore extends Store {
19 @observable appSettingsRequest = new CachedRequest(this.api.local, 'getAppSettings');
20
21 @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings'); 18 @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings');
22 19
23 fileSystemSettingsRequests = [];
24
25 fileSystemSettingsTypes = FILE_SYSTEM_SETTINGS_TYPES; 20 fileSystemSettingsTypes = FILE_SYSTEM_SETTINGS_TYPES;
26 21
27 @observable _fileSystemSettingsCache = { 22 @observable _fileSystemSettingsCache = {
@@ -36,14 +31,10 @@ export default class SettingsStore extends Store {
36 this.actions.settings.update.listen(this._update.bind(this)); 31 this.actions.settings.update.listen(this._update.bind(this));
37 this.actions.settings.remove.listen(this._remove.bind(this)); 32 this.actions.settings.remove.listen(this._remove.bind(this));
38 33
39 this.fileSystemSettingsTypes.forEach((type) => {
40 this.fileSystemSettingsRequests[type] = new CachedRequest(this.api.local, 'getAppSettings');
41 });
42
43 ipcRenderer.on('appSettings', (event, resp) => { 34 ipcRenderer.on('appSettings', (event, resp) => {
44 debug('Get appSettings resolves', resp.type, resp.data); 35 debug('Get appSettings resolves', resp.type, resp.data);
45 36
46 this._fileSystemSettingsCache[resp.type] = resp.data; 37 Object.assign(this._fileSystemSettingsCache[resp.type], resp.data);
47 }); 38 });
48 39
49 this.fileSystemSettingsTypes.forEach((type) => { 40 this.fileSystemSettingsTypes.forEach((type) => {
@@ -52,8 +43,6 @@ export default class SettingsStore extends Store {
52 } 43 }
53 44
54 async setup() { 45 async setup() {
55 // 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
56 await this.appSettingsRequest._promise;
57 await this._migrate(); 46 await this._migrate();
58 47
59 reaction( 48 reaction(
@@ -97,21 +86,6 @@ export default class SettingsStore extends Store {
97 } 86 }
98 87
99 @computed get proxy() { 88 @computed get proxy() {
100 // // We need to provide the final data structure as mobx autoruns won't work
101 // const proxySettings = observable({});
102 // this.stores.services.all.forEach((service) => {
103 // proxySettings[service.id] = {
104 // isEnabled: false,
105 // host: null,
106 // user: null,
107 // password: null,
108 // };
109 // });
110
111 // debug('this._fileSystemSettingsCache.proxy', this._fileSystemSettingsCache.proxy, proxySettings);
112
113 // return Object.assign(proxySettings, this._fileSystemSettingsCache.proxy);
114
115 return this._fileSystemSettingsCache.proxy || {}; 89 return this._fileSystemSettingsCache.proxy || {};
116 } 90 }
117 91
@@ -153,7 +127,7 @@ export default class SettingsStore extends Store {
153 data, 127 data,
154 }); 128 });
155 129
156 set(this._fileSystemSettingsCache[type], data); 130 Object.assign(this._fileSystemSettingsCache[type], data);
157 } 131 }
158 } 132 }
159 133
@@ -234,8 +208,4 @@ export default class SettingsStore extends Store {
234 }); 208 });
235 } 209 }
236 } 210 }
237
238 _getFileBasedSettings(type) {
239 ipcRenderer.send('getAppSettings', type);
240 }
241} 211}