diff options
author | 2018-11-27 18:06:14 +0100 | |
---|---|---|
committer | 2018-11-27 18:06:14 +0100 | |
commit | 62972747866740dae84fc7b519fcedd731572329 (patch) | |
tree | 3a74610caa47350ff6b3cc07482f8472f18c1764 /src/electron/Settings.js | |
parent | Fix listening key (diff) | |
download | ferdium-app-62972747866740dae84fc7b519fcedd731572329.tar.gz ferdium-app-62972747866740dae84fc7b519fcedd731572329.tar.zst ferdium-app-62972747866740dae84fc7b519fcedd731572329.zip |
feat(App): Add proxy support for services
Diffstat (limited to 'src/electron/Settings.js')
-rw-r--r-- | src/electron/Settings.js | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/electron/Settings.js b/src/electron/Settings.js index 7b04406a2..6ac3b9177 100644 --- a/src/electron/Settings.js +++ b/src/electron/Settings.js | |||
@@ -1,15 +1,21 @@ | |||
1 | import { observable, toJS } from 'mobx'; | 1 | import { observable, toJS } from 'mobx'; |
2 | import { pathExistsSync, outputJsonSync, readJsonSync } from 'fs-extra'; | 2 | import { pathExistsSync, outputJsonSync, readJsonSync } from 'fs-extra'; |
3 | import path from 'path'; | ||
3 | 4 | ||
4 | import { SETTINGS_PATH, DEFAULT_APP_SETTINGS } from '../config'; | 5 | import { SETTINGS_PATH } from '../config'; |
5 | 6 | ||
6 | const debug = require('debug')('Franz:Settings'); | 7 | const debug = require('debug')('Franz:Settings'); |
7 | 8 | ||
8 | export default class Settings { | 9 | export default class Settings { |
9 | @observable store = DEFAULT_APP_SETTINGS; | 10 | type = ''; |
11 | @observable store = {}; | ||
10 | 12 | ||
11 | constructor() { | 13 | constructor(type, defaultState = {}) { |
12 | if (!pathExistsSync(SETTINGS_PATH)) { | 14 | this.type = type; |
15 | this.store = defaultState; | ||
16 | this.defaultState = defaultState; | ||
17 | |||
18 | if (!pathExistsSync(this.settingsFile)) { | ||
13 | this._writeFile(); | 19 | this._writeFile(); |
14 | } else { | 20 | } else { |
15 | this._hydrate(); | 21 | this._hydrate(); |
@@ -31,16 +37,20 @@ export default class Settings { | |||
31 | } | 37 | } |
32 | 38 | ||
33 | _merge(settings) { | 39 | _merge(settings) { |
34 | return Object.assign(DEFAULT_APP_SETTINGS, this.store, settings); | 40 | return Object.assign(this.defaultState, this.store, settings); |
35 | } | 41 | } |
36 | 42 | ||
37 | _hydrate() { | 43 | _hydrate() { |
38 | this.store = this._merge(readJsonSync(SETTINGS_PATH)); | 44 | this.store = this._merge(readJsonSync(this.settingsFile)); |
39 | debug('Hydrate store', toJS(this.store)); | 45 | debug('Hydrate store', toJS(this.store)); |
40 | } | 46 | } |
41 | 47 | ||
42 | _writeFile() { | 48 | _writeFile() { |
43 | outputJsonSync(SETTINGS_PATH, this.store); | 49 | outputJsonSync(this.settingsFile, this.store); |
44 | debug('Write settings file', toJS(this.store)); | 50 | debug('Write settings file', toJS(this.store)); |
45 | } | 51 | } |
52 | |||
53 | get settingsFile() { | ||
54 | return path.join(SETTINGS_PATH, `${this.type === 'app' ? 'settings' : this.type}.json`); | ||
55 | } | ||
46 | } | 56 | } |