-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
82 lines (68 loc) · 1.7 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const merge = require('lodash.merge');
const defaultConfig = {
debug: false,
default: true
};
let config = defaultConfig;
let isActive = config.default;
let firstLoad = true;
const debug = function() {
if (config.debug) {
[].unshift.call(arguments, '|HYPER-ALWAYS-ON-TOP|');
console.log.apply(this, arguments);
}
};
let app_;
function setActive(newState) {
if (isActive === newState) {
return;
}
debug('setActive', newState);
isActive = newState;
if (app_) {
debug('setActive on windows', newState);
app_.getWindows().forEach(win => win.setAlwaysOnTop(isActive));
}
}
exports.decorateConfig = globalConfig => {
if (globalConfig.alwaysOnTop) {
debug('load config', globalConfig.alwaysOnTop);
config = merge(JSON.parse(JSON.stringify(defaultConfig)), globalConfig.alwaysOnTop);
if (firstLoad) {
setActive(config.default);
firstLoad = false;
}
}
return globalConfig;
};
exports.onApp = app => {
debug('onApp', isActive);
app_ = app;
app_.getWindows().forEach(win => win.setAlwaysOnTop(isActive));
};
exports.onWindow = win => {
debug('onWindow', isActive);
win.setAlwaysOnTop(isActive);
};
exports.decorateMenu = menu => {
debug('decorateMenu isActive', isActive);
return menu.map(menuItem => {
if (menuItem.label !== 'View') {
return menuItem;
}
const newMenuItem = Object.assign({}, menuItem);
newMenuItem.submenu = [...newMenuItem.submenu];
newMenuItem.submenu.push({
type: 'separator'
});
newMenuItem.submenu.push({
label: 'Float on Top',
type: 'checkbox',
checked: isActive,
click: item => {
setActive(item.checked);
}
});
return newMenuItem;
});
};