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.js55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js
new file mode 100644
index 000000000..816f545ee
--- /dev/null
+++ b/src/stores/SettingsStore.js
@@ -0,0 +1,55 @@
1import { ipcRenderer } from 'electron';
2import { action, computed, observable } from 'mobx';
3
4import Store from './lib/Store';
5import Request from './lib/Request';
6import CachedRequest from './lib/CachedRequest';
7import { gaEvent } from '../lib/analytics';
8
9export default class SettingsStore extends Store {
10 @observable allSettingsRequest = new CachedRequest(this.api.local, 'getSettings');
11 @observable updateSettingsRequest = new Request(this.api.local, 'updateSettings');
12 @observable removeSettingsKeyRequest = new Request(this.api.local, 'removeKey');
13
14 constructor(...args) {
15 super(...args);
16
17 // Register action handlers
18 this.actions.settings.update.listen(this._update.bind(this));
19 this.actions.settings.remove.listen(this._remove.bind(this));
20
21 // this.registerReactions([
22 // this._shareSettingsWithMainProcess.bind(this),
23 // ]);
24 }
25
26 setup() {
27 this.allSettingsRequest.execute();
28 this._shareSettingsWithMainProcess();
29 }
30
31 @computed get all() {
32 return this.allSettingsRequest.result || {};
33 }
34
35 @action async _update({ settings }) {
36 await this.updateSettingsRequest.execute(settings)._promise;
37 await this.allSettingsRequest.invalidate({ immediately: true });
38
39 this._shareSettingsWithMainProcess();
40
41 gaEvent('Settings', 'update');
42 }
43
44 @action async _remove({ key }) {
45 await this.removeSettingsKeyRequest.execute(key);
46 await this.allSettingsRequest.invalidate({ immediately: true });
47
48 this._shareSettingsWithMainProcess();
49 }
50
51 // Reactions
52 _shareSettingsWithMainProcess() {
53 ipcRenderer.send('settings', this.all);
54 }
55}