forked from ElectronNET/Electron.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtray.ts
More file actions
128 lines (108 loc) · 3.38 KB
/
Copy pathtray.ts
File metadata and controls
128 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { Menu, Tray, nativeImage } from "electron";
const path = require('path');
let tray: Electron.Tray;
module.exports = (socket: SocketIO.Server) => {
socket.on('register-tray-click', (id) => {
if (tray) {
tray.on('click', (event, bounds) => {
socket.emit('tray-click-event' + id, [(<any>event).__proto__, bounds]);
});
}
});
socket.on('register-tray-right-click', (id) => {
if (tray) {
tray.on('right-click', (event, bounds) => {
socket.emit('tray-right-click-event' + id, [(<any>event).__proto__, bounds]);
});
}
});
socket.on('register-tray-double-click', (id) => {
if (tray) {
tray.on('double-click', (event, bounds) => {
socket.emit('tray-double-click-event' + id, [(<any>event).__proto__, bounds]);
});
}
});
socket.on('register-tray-balloon-show', (id) => {
if (tray) {
tray.on('balloon-show', () => {
socket.emit('tray-balloon-show-event' + id);
});
}
});
socket.on('register-tray-balloon-click', (id) => {
if (tray) {
tray.on('balloon-click', () => {
socket.emit('tray-balloon-click-event' + id);
});
}
});
socket.on('register-tray-balloon-closed', (id) => {
if (tray) {
tray.on('balloon-closed', () => {
socket.emit('tray-balloon-closed-event' + id);
});
}
});
socket.on('create-tray', (image, menuItems) => {
const menu = Menu.buildFromTemplate(menuItems);
addMenuItemClickConnector(menu.items, (id) => {
socket.emit("trayMenuItemClicked", id);
});
const imagePath = path.join(__dirname.replace('api', ''), 'bin', image);
tray = new Tray(imagePath);
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) {
let img = 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-setHighlightMode', (mode) => {
if (tray) {
tray.setHighlightMode(mode);
}
});
socket.on('tray-displayBalloon', (options) => {
if (tray) {
tray.displayBalloon(options);
}
});
socket.on('tray-isDestroyed', () => {
if (tray) {
let isDestroyed = tray.isDestroyed();
socket.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); };
}
});
}
}