-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
56 lines (47 loc) · 1.14 KB
/
index.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
const defaultConfig = {
focus: 0.9,
blur: 0.9
}
let opacityConfig = null
const browserWindowQueue = []
const browserWindows = []
const setOpacity = win => {
if (!win.isDestroyed()) {
if (win.isFocused()) {
win.setOpacity(opacityConfig.focus)
} else {
win.setOpacity(opacityConfig.blur)
}
win.on('blur', () => {
win.setOpacity(opacityConfig.blur)
})
win.on('focus', () => {
win.setOpacity(opacityConfig.focus)
})
}
}
const trySetOpacity = () => {
if (opacityConfig) {
let _win
while ((_win = browserWindowQueue.shift())) {
setOpacity(_win)
}
}
}
module.exports.decorateConfig = config => {
let _opacityConfig = config.opacity
if (typeof _opacityConfig === 'number') {
_opacityConfig = { focus: _opacityConfig, blur: _opacityConfig }
} else if (typeof _opacityConfig !== 'object') {
_opacityConfig = {}
}
opacityConfig = Object.assign({}, defaultConfig, _opacityConfig)
browserWindowQueue.push(...browserWindows)
trySetOpacity()
return config
}
module.exports.onWindow = win => {
browserWindowQueue.push(win)
browserWindows.push(win)
trySetOpacity()
}