-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.js
65 lines (56 loc) · 1.51 KB
/
menu.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
const {app, Menu, Notification, Tray} = require('electron')
const os = require('os')
const template = [
{
label: 'File',
submenu: [
{
label: 'Reload',
accelerator: 'CmdOrCtrl+R',
click(item, focusedWindow) {
if (focusedWindow) focusedWindow.reload()
}
},
{
label: 'Quit',
accelerator: 'CmdOrCtrl+Q',
click() {
app.quit()
}
}
]
},
{
label: 'Tools',
submenu: [{
label: 'Dev Tools',
accelerator: process.platform === 'darwin' ? 'Cmd+Shift+I' : 'Alt+I',
click(item, focusedWindow) {
if (focusedWindow) focusedWindow.webContents.toggleDevTools()
}
},
{
label: 'Show Free Memory',
accelerator: 'CmdOrCtrl+F',
click() {
let freeMem = String(os.freemem())
let notification = new Notification({
title: 'Memory',
body:'You Have ' + freeMem.substring(0,4) + ' mb free memory'
})
notification.show()
}
}]
}]
if (process.platform === 'darwin') {
template.unshift({})
}
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
const tray = new Tray('./static/favicon.ico')
const trayMenu = Menu.buildFromTemplate([
{label: 'Options', type: 'radio'},
{label: 'Exit', click(){ app.quit()}}
])
tray.setToolTip('Bookstore Native Application')
tray.setContextMenu(trayMenu)