-
Notifications
You must be signed in to change notification settings - Fork 40
/
main.js
63 lines (57 loc) · 1.44 KB
/
main.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
const {Menu} = require('electron')
const platform = require('os').platform()
const path = require('path')
const {menubar} = require('menubar')
const initialIcon = path.join(__dirname, 'img/png/blank.png')
const mb = menubar({
preloadWindow: true,
icon: initialIcon,
browserWindow: {
width: 220,
height: 206,
webPreferences: {
nodeIntegration: true,
enableRemoteModule: true
}
}
})
// Make menubar accessible to the renderer
global.sharedObject = {mb}
mb.on('ready', () => {
console.log('app is ready')
// Workaround to fix window position when statusbar at top for win32
if (platform === 'win32' && mb.tray.getBounds().y < 5) {
mb.setOption('windowPosition', 'trayCenter')
}
})
mb.on('after-create-window', () => {
mb.window.loadURL(`file://${__dirname}/index.html`) // eslint-disable-line n/no-path-concat
const contextMenu = Menu.buildFromTemplate([
{
label: 'Sound',
submenu: [
{
label: 'On',
type: 'radio',
checked: true,
click: () => mb.window.webContents.send('TOGGLE_SOUND', true)
},
{
label: 'Off',
type: 'radio',
checked: false,
click: () => mb.window.webContents.send('TOGGLE_SOUND', false)
}
]
},
{
label: 'Quit',
click() {
mb.app.quit()
}
}
])
mb.tray.on('right-click', () => {
mb.tray.popUpContextMenu(contextMenu)
})
})