forked from nukeop/nuclear
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.js
38 lines (29 loc) · 814 Bytes
/
store.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
let { app } = require('electron').remote;
import electronStore from 'electron-store';
import options from '../constants/settings';
const store = new electronStore();
function initStore() {
if (!store.get('lastFm')) {
store.set('lastFm', {});
}
if (!store.get('settings')) {
store.set('settings', {});
}
if (!store.get('playlists')) {
store.set('playlists', []);
}
}
initStore();
function getOption(key) {
let settings = store.get('settings') || {};
let value = settings[key];
if (value === undefined) {
value = _.find(options, { name: key }).default;
}
return value;
}
function setOption(key, value) {
let settings = store.get('settings') || {};
store.set('settings', Object.assign({}, settings, { [`${key}`]: value }));
}
export { store, getOption, setOption };