aboutsummaryrefslogtreecommitdiffstats
path: root/src/electron/Settings.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/electron/Settings.js')
-rw-r--r--src/electron/Settings.js39
1 files changed, 27 insertions, 12 deletions
diff --git a/src/electron/Settings.js b/src/electron/Settings.js
index 824b4c20c..b3138e948 100644
--- a/src/electron/Settings.js
+++ b/src/electron/Settings.js
@@ -1,27 +1,42 @@
1import { observable } from 'mobx'; 1import { observable, toJS } from 'mobx';
2import { pathExistsSync, outputJsonSync, readJsonSync } from 'fs-extra';
2 3
3import { DEFAULT_APP_SETTINGS } from '../config'; 4import { SETTINGS_PATH, DEFAULT_APP_SETTINGS } from '../config';
5
6const debug = require('debug')('Settings');
4 7
5export default class Settings { 8export default class Settings {
6 @observable store = { 9 @observable store = DEFAULT_APP_SETTINGS;
7 autoLaunchOnStart: DEFAULT_APP_SETTINGS.autoLaunchOnStart, 10
8 autoLaunchInBackground: DEFAULT_APP_SETTINGS.autoLaunchInBackground, 11 constructor() {
9 runInBackground: DEFAULT_APP_SETTINGS.runInBackground, 12 if (!pathExistsSync(SETTINGS_PATH)) {
10 enableSystemTray: DEFAULT_APP_SETTINGS.enableSystemTray, 13 this._writeFile();
11 minimizeToSystemTray: DEFAULT_APP_SETTINGS.minimizeToSystemTray, 14 } else {
12 locale: DEFAULT_APP_SETTINGS.locale, 15 this._hydrate();
13 beta: DEFAULT_APP_SETTINGS.beta, 16 }
14 }; 17 }
15 18
16 set(settings) { 19 set(settings) {
17 this.store = Object.assign(this.store, settings); 20 this.store = Object.assign(this.store, settings);
21
22 this._writeFile();
18 } 23 }
19 24
20 all() { 25 get all() {
21 return this.store; 26 return this.store;
22 } 27 }
23 28
24 get(key) { 29 get(key) {
25 return this.store[key]; 30 return this.store[key];
26 } 31 }
32
33 _hydrate() {
34 this.store = readJsonSync(SETTINGS_PATH);
35 debug('Hydrate store', toJS(this.store));
36 }
37
38 _writeFile() {
39 outputJsonSync(SETTINGS_PATH, this.store);
40 debug('Write settings file', toJS(this.store));
41 }
27} 42}