aboutsummaryrefslogtreecommitdiffstats
path: root/src/stores/SettingsStore.js
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2018-03-27 21:25:56 +0200
committerLibravatar Stefan Malzner <stefan@adlk.io>2018-03-27 21:25:56 +0200
commit8aab8699e02ed9ec736bb6dfab0edd3fe9156c8d (patch)
tree9b853e0d343f4bf2f60625431275bdc2dd08e027 /src/stores/SettingsStore.js
parentMove "locale" to user data (diff)
downloadferdium-app-8aab8699e02ed9ec736bb6dfab0edd3fe9156c8d.tar.gz
ferdium-app-8aab8699e02ed9ec736bb6dfab0edd3fe9156c8d.tar.zst
ferdium-app-8aab8699e02ed9ec736bb6dfab0edd3fe9156c8d.zip
Split settings into multiple stores; app specific settings are now stored in config file
Diffstat (limited to 'src/stores/SettingsStore.js')
-rw-r--r--src/stores/SettingsStore.js41
1 files changed, 27 insertions, 14 deletions
diff --git a/src/stores/SettingsStore.js b/src/stores/SettingsStore.js
index b7d803398..b3f5d3eaf 100644
--- a/src/stores/SettingsStore.js
+++ b/src/stores/SettingsStore.js
@@ -1,12 +1,18 @@
1import { ipcRenderer } from 'electron'; 1import { ipcRenderer } from 'electron';
2import { action, computed } from 'mobx'; 2import { action, computed, observable } from 'mobx';
3import localStorage from 'mobx-localstorage'; 3import localStorage from 'mobx-localstorage';
4 4
5import Store from './lib/Store'; 5import Store from './lib/Store';
6import { gaEvent } from '../lib/analytics';
7import SettingsModel from '../models/Settings'; 6import SettingsModel from '../models/Settings';
7import Request from './lib/Request';
8import CachedRequest from './lib/CachedRequest';
9
10const debug = require('debug')('SettingsStore');
8 11
9export default class SettingsStore extends Store { 12export default class SettingsStore extends Store {
13 @observable appSettingsRequest = new CachedRequest(this.api.local, 'getAppSettings');
14 @observable updateAppSettingsRequest = new Request(this.api.local, 'updateAppSettings');
15
10 constructor(...args) { 16 constructor(...args) {
11 super(...args); 17 super(...args);
12 18
@@ -15,22 +21,29 @@ export default class SettingsStore extends Store {
15 this.actions.settings.remove.listen(this._remove.bind(this)); 21 this.actions.settings.remove.listen(this._remove.bind(this));
16 } 22 }
17 23
18 setup() {
19 this._shareSettingsWithMainProcess();
20 }
21
22 @computed get all() { 24 @computed get all() {
23 return new SettingsModel(localStorage.getItem('app') || {}); 25 return new SettingsModel({
26 app: this.appSettingsRequest.execute().result || {},
27 service: localStorage.getItem('service') || {},
28 group: localStorage.getItem('group') || {},
29 stats: localStorage.getItem('stats') || {},
30 });
24 } 31 }
25 32
26 @action async _update({ settings }) { 33 @action async _update({ type, data }) {
34 debug('Update settings', type, data, this.all);
27 const appSettings = this.all; 35 const appSettings = this.all;
28 localStorage.setItem('app', Object.assign(appSettings, settings)); 36 if (type !== 'app') {
29 37 localStorage.setItem(type, Object.assign(appSettings[type], data));
30 // We need a little hack to wait until everything is patched 38 } else {
31 setTimeout(() => this._shareSettingsWithMainProcess(), 0); 39 debug('Store app settings on file system', type, data);
32 40 this.updateAppSettingsRequest.execute(data);
33 gaEvent('Settings', 'update'); 41
42 this.appSettingsRequest.patch((result) => {
43 if (!result) return;
44 Object.assign(result, data);
45 });
46 }
34 } 47 }
35 48
36 @action async _remove({ key }) { 49 @action async _remove({ key }) {