-
Notifications
You must be signed in to change notification settings - Fork 1
/
myApp.js
61 lines (52 loc) · 1.34 KB
/
myApp.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
const electron = require('electron');
const { globalShortcut } = electron;
const { menubar } = require('menubar');
const mb = menubar({
browserWindow: {
webPreferences: {
nodeIntegration: true
},
transparent: true,
width: 800,
height: 800,
},
icon: 'icon.png',
});
let isShown = false;
mb.on('ready', () => {
const ret = globalShortcut.register('CommandOrControl+shift+X', (short) => {
isShown ? mb.hideWindow() : mb.showWindow()
})
if (!ret) {
console.log('registration failed')
}
// Check whether a shortcut is registered.
console.log(globalShortcut.isRegistered('CommandOrControl+X'))
console.log('app is ready');
// your app code here
});
mb
.on('will-quit', () => {
// Unregister a shortcut.
globalShortcut.unregister('CommandOrControl+X')
globalShortcut.unregister('Esc')
})
.on('after-show', () => {
const escTrigger = globalShortcut.register('Esc', (short) => {
mb.hideWindow()
})
isShown = true
})
.on('after-hide', () => {
globalShortcut.unregister('Esc')
isShown = false
electron.Menu.sendActionToFirstResponder('hide:')
})
.on('focus-lost', () => {
globalShortcut.unregister('Esc')
isShown = false
electron.Menu.sendActionToFirstResponder('hide:')
})
.on('after-create-window', () => {
// mb.window.openDevTools()
})