aboutsummaryrefslogtreecommitdiffstats
path: root/src/electron/Settings.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/electron/Settings.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/electron/Settings.js')
-rw-r--r--src/electron/Settings.js34
1 files changed, 30 insertions, 4 deletions
diff --git a/src/electron/Settings.js b/src/electron/Settings.js
index 824b4c20c..e24aefdbb 100644
--- a/src/electron/Settings.js
+++ b/src/electron/Settings.js
@@ -1,27 +1,53 @@
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 = {
7 autoLaunchOnStart: DEFAULT_APP_SETTINGS.autoLaunchOnStart,
8 autoLaunchInBackground: DEFAULT_APP_SETTINGS.autoLaunchInBackground, 10 autoLaunchInBackground: DEFAULT_APP_SETTINGS.autoLaunchInBackground,
9 runInBackground: DEFAULT_APP_SETTINGS.runInBackground, 11 runInBackground: DEFAULT_APP_SETTINGS.runInBackground,
10 enableSystemTray: DEFAULT_APP_SETTINGS.enableSystemTray, 12 enableSystemTray: DEFAULT_APP_SETTINGS.enableSystemTray,
11 minimizeToSystemTray: DEFAULT_APP_SETTINGS.minimizeToSystemTray, 13 minimizeToSystemTray: DEFAULT_APP_SETTINGS.minimizeToSystemTray,
12 locale: DEFAULT_APP_SETTINGS.locale, 14 locale: DEFAULT_APP_SETTINGS.locale,
13 beta: DEFAULT_APP_SETTINGS.beta, 15 beta: DEFAULT_APP_SETTINGS.beta,
16 isAppMuted: DEFAULT_APP_SETTINGS.isAppMuted,
17 showMessageBadgeWhenMuted: DEFAULT_APP_SETTINGS.showMessageBadgeWhenMuted,
18 showDisabledServices: DEFAULT_APP_SETTINGS.showDisabledServices,
19 enableSpellchecking: DEFAULT_APP_SETTINGS.enableSpellchecking,
14 }; 20 };
15 21
22 constructor() {
23 if (!pathExistsSync(SETTINGS_PATH)) {
24 this._writeFile();
25 } else {
26 this._hydrate();
27 }
28 }
29
16 set(settings) { 30 set(settings) {
17 this.store = Object.assign(this.store, settings); 31 this.store = Object.assign(this.store, settings);
32
33 this._writeFile();
18 } 34 }
19 35
20 all() { 36 get all() {
21 return this.store; 37 return this.store;
22 } 38 }
23 39
24 get(key) { 40 get(key) {
25 return this.store[key]; 41 return this.store[key];
26 } 42 }
43
44 _hydrate() {
45 this.store = readJsonSync(SETTINGS_PATH);
46 debug('Hydrate store', toJS(this.store));
47 }
48
49 _writeFile() {
50 outputJsonSync(SETTINGS_PATH, this.store);
51 debug('Write settings file', toJS(this.store));
52 }
27} 53}