-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings-manager.js
51 lines (42 loc) · 1003 Bytes
/
settings-manager.js
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
const homedir = require('os').homedir
const app = require('electron').app
const settings = require('electron-settings')
const objectPath = require('object-path')
const DEFAULTS = {
filePath: null,
do_api_key: null,
ip_auth: false,
ips: null
};
// we need to sync every setting that can be modified externally
// e.g. the `openOnStartup` setting can be modified via
// macOS' System Preferences.app
function sync() {
settings.setSync('openOnStartup', app.getLoginItemSettings().openAtLogin);
}
function init() {
settings.defaults(DEFAULTS);
settings.applyDefaultsSync();
sync();
}
function get(key) {
sync();
return objectPath.get(key) || settings.getSync(key);
}
function getAll() {
sync();
return settings.getSync();
}
function set(key, value) {
settings.setSync(key, value);
}
function observe(keyPath, handler) {
return settings.observe(keyPath, handler);
}
module.exports = {
get: get,
getAll: getAll,
set: set,
observe: observe,
init: init
};