aboutsummaryrefslogtreecommitdiffstats
path: root/src/electron
diff options
context:
space:
mode:
authorLibravatar Stefan Malzner <stefan@adlk.io>2018-11-22 14:14:25 +0100
committerLibravatar Stefan Malzner <stefan@adlk.io>2018-11-22 14:14:25 +0100
commit46b8c8c4b3a5b80e0187b284abc84566a7e784db (patch)
tree7fd378bcdd18e78c42dfeb61a15f89fd10106046 /src/electron
parentADD features loading spinner (diff)
parentfeat(App): Add option to enable dark mode for supported services (diff)
downloadferdium-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.js45
-rw-r--r--src/electron/ipc-api/settings.js6
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 @@
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}
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 @@
1import { ipcMain } from 'electron'; 1import { ipcMain } from 'electron';
2 2
3export default (params) => { 3export 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};