forked from ElectronNET/Electron.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtray.js
More file actions
108 lines (108 loc) · 3.38 KB
/
tray.js
File metadata and controls
108 lines (108 loc) · 3.38 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
"use strict";
const electron_1 = require("electron");
let tray;
let electronSocket;
module.exports = (socket) => {
electronSocket = socket;
socket.on('register-tray-click', (id) => {
if (tray) {
tray.on('click', (event, bounds) => {
electronSocket.emit('tray-click-event' + id, [event.__proto__, bounds]);
});
}
});
socket.on('register-tray-right-click', (id) => {
if (tray) {
tray.on('right-click', (event, bounds) => {
electronSocket.emit('tray-right-click-event' + id, [event.__proto__, bounds]);
});
}
});
socket.on('register-tray-double-click', (id) => {
if (tray) {
tray.on('double-click', (event, bounds) => {
electronSocket.emit('tray-double-click-event' + id, [event.__proto__, bounds]);
});
}
});
socket.on('register-tray-balloon-show', (id) => {
if (tray) {
tray.on('balloon-show', () => {
electronSocket.emit('tray-balloon-show-event' + id);
});
}
});
socket.on('register-tray-balloon-click', (id) => {
if (tray) {
tray.on('balloon-click', () => {
electronSocket.emit('tray-balloon-click-event' + id);
});
}
});
socket.on('register-tray-balloon-closed', (id) => {
if (tray) {
tray.on('balloon-closed', () => {
electronSocket.emit('tray-balloon-closed-event' + id);
});
}
});
socket.on('create-tray', (image, menuItems) => {
const trayIcon = electron_1.nativeImage.createFromPath(image);
tray = new electron_1.Tray(trayIcon);
if (menuItems) {
const menu = electron_1.Menu.buildFromTemplate(menuItems);
addMenuItemClickConnector(menu.items, (id) => {
electronSocket.emit('trayMenuItemClicked', id);
});
tray.setContextMenu(menu);
}
});
socket.on('tray-destroy', () => {
if (tray) {
tray.destroy();
}
});
socket.on('tray-setImage', (image) => {
if (tray) {
tray.setImage(image);
}
});
socket.on('tray-setPressedImage', (image) => {
if (tray) {
const img = electron_1.nativeImage.createFromPath(image);
tray.setPressedImage(img);
}
});
socket.on('tray-setToolTip', (toolTip) => {
if (tray) {
tray.setToolTip(toolTip);
}
});
socket.on('tray-setTitle', (title) => {
if (tray) {
tray.setTitle(title);
}
});
socket.on('tray-displayBalloon', (options) => {
if (tray) {
tray.displayBalloon(options);
}
});
socket.on('tray-isDestroyed', () => {
if (tray) {
const isDestroyed = tray.isDestroyed();
electronSocket.emit('tray-isDestroyedCompleted', isDestroyed);
}
});
function addMenuItemClickConnector(menuItems, callback) {
menuItems.forEach((item) => {
if (item.submenu && item.submenu.items.length > 0) {
addMenuItemClickConnector(item.submenu.items, callback);
}
if ('id' in item && item.id) {
item.click = () => { callback(item.id); };
}
});
}
};
//# sourceMappingURL=tray.js.map