diff options
author | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
---|---|---|
committer | Stefan Malzner <stefan@adlk.io> | 2017-10-13 12:29:40 +0200 |
commit | 58cda9cc7fb79ca9df6746de7f9662bc08dc156a (patch) | |
tree | 1211600c2a5d3b5f81c435c6896618111a611720 /src/stores/SettingsStore.js | |
download | ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.gz ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.tar.zst ferdium-app-58cda9cc7fb79ca9df6746de7f9662bc08dc156a.zip |
initial commit
Diffstat (limited to 'src/stores/SettingsStore.js')
-rw-r--r-- | src/stores/SettingsStore.js | 55 |
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 @@ | |||
1 | import { ipcRenderer } from 'electron'; | ||
2 | import { action, computed, observable } from 'mobx'; | ||
3 | |||
4 | import Store from './lib/Store'; | ||
5 | import Request from './lib/Request'; | ||
6 | import CachedRequest from './lib/CachedRequest'; | ||
7 | import { gaEvent } from '../lib/analytics'; | ||
8 | |||
9 | export 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 | } | ||