-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtray.js
More file actions
83 lines (71 loc) · 1.78 KB
/
tray.js
File metadata and controls
83 lines (71 loc) · 1.78 KB
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
83
/**
* tray.js - System Tray functionality for Fileway
* Keeps app running in background when window is closed
*/
const { Tray, Menu, nativeImage } = require('electron');
const path = require('path');
let tray = null;
function createTray(mainWindow, iconPath) {
// Create tray icon
const icon = nativeImage.createFromPath(iconPath);
tray = new Tray(icon.resize({ width: 16, height: 16 }));
tray.setToolTip('Fileway - LAN File Sharing');
// Context menu
const contextMenu = Menu.buildFromTemplate([
{
label: 'Show Fileway',
click: () => {
mainWindow.show();
mainWindow.focus();
}
},
{
type: 'separator'
},
{
label: 'Quit',
click: () => {
// Set flag to indicate intentional quit
global.isQuitting = true;
require('electron').app.quit();
}
}
]);
tray.setContextMenu(contextMenu);
// Click on tray icon shows/hides window
tray.on('click', () => {
if (mainWindow.isVisible()) {
mainWindow.hide();
} else {
mainWindow.show();
mainWindow.focus();
}
});
// Double-click shows window
tray.on('double-click', () => {
mainWindow.show();
mainWindow.focus();
});
return tray;
}
function showTrayNotification(title, body) {
if (tray) {
tray.displayBalloon({
title: title,
content: body,
icon: null,
respectQuietTime: false
});
}
}
function destroyTray() {
if (tray) {
tray.destroy();
tray = null;
}
}
module.exports = {
createTray,
showTrayNotification,
destroyTray
};