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.js45
1 files changed, 32 insertions, 13 deletions
diff --git a/src/electron/Settings.js b/src/electron/Settings.js
index 824b4c20c..7b04406a2 100644
--- a/src/electron/Settings.js
+++ b/src/electron/Settings.js
@@ -1,27 +1,46 @@
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')('Franz: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 = this._merge(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 _merge(settings) {
34 return Object.assign(DEFAULT_APP_SETTINGS, this.store, settings);
35 }
36
37 _hydrate() {
38 this.store = this._merge(readJsonSync(SETTINGS_PATH));
39 debug('Hydrate store', toJS(this.store));
40 }
41
42 _writeFile() {
43 outputJsonSync(SETTINGS_PATH, this.store);
44 debug('Write settings file', toJS(this.store));
45 }
27} 46}