-
Notifications
You must be signed in to change notification settings - Fork 456
/
config.js
58 lines (53 loc) · 1.62 KB
/
config.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
52
53
54
55
56
57
58
import { ipcRenderer } from 'electron'
import Store from 'electron-store'
import themes from './themes'
const schema = {
locale: { type: 'string', default: 'en-US' },
lang: { type: 'string', default: 'en' },
country: { type: 'string', default: 'US' },
theme: { type: 'string', default: themes[0].value },
hotkey: { type: 'string', default: 'Control+Space' },
showInTray: { type: 'boolean', default: true },
firstStart: { type: 'boolean', default: true },
developerMode: { type: 'boolean', default: false },
cleanOnHide: { type: 'boolean', default: true },
selectOnShow: { type: 'boolean', default: false },
hideOnBlur: { type: 'boolean', default: true },
plugins: { type: 'object', default: {} },
isMigratedPlugins: { type: 'boolean', default: false },
openAtLogin: { type: 'boolean', default: true },
winPosition: { type: 'array', default: [] },
}
const store = new Store({
schema,
migrations: {
'>=0.9.0': (oldStore) => {
oldStore.delete('positions')
},
'>=0.10.0': (oldStore) => {
oldStore.delete('crashreportingEnabled')
}
}
})
/**
* Get a value from global configuration
* @param {String} key
* @return {Any}
*/
const get = (key) => store.get(key)
/**
* Write a value to global config. It immedately rewrites global config
* and notifies all listeners about changes
*
* @param {String} key
* @param {Any} value
*/
const set = (key, value) => {
store.set(key, value)
if (ipcRenderer) {
console.log('notify main process', key, value)
// Notify main process about settings changes
ipcRenderer.send('updateSettings', key, value)
}
}
export default { get, set }