1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
import { observable, toJS } from 'mobx';
import { pathExistsSync, outputJsonSync, readJsonSync } from 'fs-extra';
import { SETTINGS_PATH, DEFAULT_APP_SETTINGS } from '../config';
const debug = require('debug')('Settings');
export default class Settings {
@observable store = {
autoLaunchInBackground: DEFAULT_APP_SETTINGS.autoLaunchInBackground,
runInBackground: DEFAULT_APP_SETTINGS.runInBackground,
enableSystemTray: DEFAULT_APP_SETTINGS.enableSystemTray,
minimizeToSystemTray: DEFAULT_APP_SETTINGS.minimizeToSystemTray,
locale: DEFAULT_APP_SETTINGS.locale,
beta: DEFAULT_APP_SETTINGS.beta,
isAppMuted: DEFAULT_APP_SETTINGS.isAppMuted,
showMessageBadgeWhenMuted: DEFAULT_APP_SETTINGS.showMessageBadgeWhenMuted,
showDisabledServices: DEFAULT_APP_SETTINGS.showDisabledServices,
enableSpellchecking: DEFAULT_APP_SETTINGS.enableSpellchecking,
};
constructor() {
if (!pathExistsSync(SETTINGS_PATH)) {
this._writeFile();
} else {
this._hydrate();
}
}
set(settings) {
this.store = Object.assign(this.store, settings);
this._writeFile();
}
get all() {
return this.store;
}
get(key) {
return this.store[key];
}
_hydrate() {
this.store = readJsonSync(SETTINGS_PATH);
debug('Hydrate store', toJS(this.store));
}
_writeFile() {
outputJsonSync(SETTINGS_PATH, this.store);
debug('Write settings file', toJS(this.store));
}
}
|