diff options
author | 2018-03-27 21:25:56 +0200 | |
---|---|---|
committer | 2018-03-27 21:25:56 +0200 | |
commit | 8aab8699e02ed9ec736bb6dfab0edd3fe9156c8d (patch) | |
tree | 9b853e0d343f4bf2f60625431275bdc2dd08e027 /src/electron | |
parent | Move "locale" to user data (diff) | |
download | ferdium-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')
-rw-r--r-- | src/electron/Settings.js | 34 | ||||
-rw-r--r-- | src/electron/ipc-api/settings.js | 8 |
2 files changed, 38 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 @@ | |||
1 | import { observable } from 'mobx'; | 1 | import { observable, toJS } from 'mobx'; |
2 | import { pathExistsSync, outputJsonSync, readJsonSync } from 'fs-extra'; | ||
2 | 3 | ||
3 | import { DEFAULT_APP_SETTINGS } from '../config'; | 4 | import { SETTINGS_PATH, DEFAULT_APP_SETTINGS } from '../config'; |
5 | |||
6 | const debug = require('debug')('Settings'); | ||
4 | 7 | ||
5 | export default class Settings { | 8 | export 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 | } |
diff --git a/src/electron/ipc-api/settings.js b/src/electron/ipc-api/settings.js index 995b28fbd..00bdc0113 100644 --- a/src/electron/ipc-api/settings.js +++ b/src/electron/ipc-api/settings.js | |||
@@ -4,4 +4,12 @@ export default (params) => { | |||
4 | ipcMain.on('settings', (event, args) => { | 4 | ipcMain.on('settings', (event, args) => { |
5 | params.settings.set(args); | 5 | params.settings.set(args); |
6 | }); | 6 | }); |
7 | |||
8 | ipcMain.on('getAppSettings', () => { | ||
9 | params.mainWindow.webContents.send('appSettings', params.settings.all); | ||
10 | }); | ||
11 | |||
12 | ipcMain.on('updateAppSettings', (event, args) => { | ||
13 | params.settings.set(args); | ||
14 | }); | ||
7 | }; | 15 | }; |