-
Notifications
You must be signed in to change notification settings - Fork 29
/
tray.js
35 lines (30 loc) · 805 Bytes
/
tray.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
const { app, Menu, Tray, nativeImage } = require('electron')
const path = require('path')
const config = require('./config')
const noop = () => {}
/**
* Creates a tray icon and adds a context menu to it.
* @param {Function} onToggle
* @param {Function} onClick
* @return {Tray}
*/
function create({ onToggle = noop(), onClick = noop() }) {
if (process.platform === 'darwin') return
const icon = path.join(__dirname, config.get('icons.tray'))
const tray = new Tray(nativeImage.createFromPath(icon))
const contextMenu = Menu.buildFromTemplate([
{
label: 'Toggle',
click() {
onToggle()
},
},
{ type: 'separator' },
{ role: 'quit' },
])
tray.setToolTip(app.getName())
tray.setContextMenu(contextMenu)
tray.on('click', onClick)
return tray
}
module.exports = { create }