diff options
author | 2018-11-22 14:14:25 +0100 | |
---|---|---|
committer | 2018-11-22 14:14:25 +0100 | |
commit | 46b8c8c4b3a5b80e0187b284abc84566a7e784db (patch) | |
tree | 7fd378bcdd18e78c42dfeb61a15f89fd10106046 /src/electron | |
parent | ADD features loading spinner (diff) | |
parent | feat(App): Add option to enable dark mode for supported services (diff) | |
download | ferdium-app-46b8c8c4b3a5b80e0187b284abc84566a7e784db.tar.gz ferdium-app-46b8c8c4b3a5b80e0187b284abc84566a7e784db.tar.zst ferdium-app-46b8c8c4b3a5b80e0187b284abc84566a7e784db.zip |
Merge branch 'develop' into feature/features-api
Diffstat (limited to 'src/electron')
-rw-r--r-- | src/electron/Settings.js | 45 | ||||
-rw-r--r-- | src/electron/ipc-api/settings.js | 6 |
2 files changed, 37 insertions, 14 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 @@ | |||
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')('Franz:Settings'); | ||
4 | 7 | ||
5 | export default class Settings { | 8 | export 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 | } |
diff --git a/src/electron/ipc-api/settings.js b/src/electron/ipc-api/settings.js index 995b28fbd..3eab68a91 100644 --- a/src/electron/ipc-api/settings.js +++ b/src/electron/ipc-api/settings.js | |||
@@ -1,7 +1,11 @@ | |||
1 | import { ipcMain } from 'electron'; | 1 | import { ipcMain } from 'electron'; |
2 | 2 | ||
3 | export default (params) => { | 3 | export default (params) => { |
4 | ipcMain.on('settings', (event, args) => { | 4 | ipcMain.on('getAppSettings', () => { |
5 | params.mainWindow.webContents.send('appSettings', params.settings.all); | ||
6 | }); | ||
7 | |||
8 | ipcMain.on('updateAppSettings', (event, args) => { | ||
5 | params.settings.set(args); | 9 | params.settings.set(args); |
6 | }); | 10 | }); |
7 | }; | 11 | }; |