forked from ElectronNET/Electron.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdock.ts
More file actions
77 lines (60 loc) · 1.99 KB
/
dock.ts
File metadata and controls
77 lines (60 loc) · 1.99 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
import { app, Menu } from 'electron';
let electronSocket;
export = (socket: SocketIO.Socket) => {
electronSocket = socket;
socket.on('dock-bounce', (type) => {
const id = app.dock.bounce(type);
electronSocket.emit('dock-bounce-completed', id);
});
socket.on('dock-cancelBounce', (id) => {
app.dock.cancelBounce(id);
});
socket.on('dock-downloadFinished', (filePath) => {
app.dock.downloadFinished(filePath);
});
socket.on('dock-setBadge', (text) => {
app.dock.setBadge(text);
});
socket.on('dock-getBadge', () => {
const text = app.dock.getBadge();
electronSocket.emit('dock-getBadge-completed', text);
});
socket.on('dock-hide', () => {
app.dock.hide();
});
socket.on('dock-show', () => {
app.dock.show();
});
socket.on('dock-isVisible', () => {
const isVisible = app.dock.isVisible();
electronSocket.emit('dock-isVisible-completed', isVisible);
});
socket.on('dock-setMenu', (menuItems) => {
let menu = null;
if (menuItems) {
menu = Menu.buildFromTemplate(menuItems);
addMenuItemClickConnector(menu.items, (id) => {
electronSocket.emit('dockMenuItemClicked', id);
});
}
app.dock.setMenu(menu);
});
// TODO: Menu (macOS) still to be implemented
socket.on('dock-getMenu', () => {
const menu = app.dock.getMenu();
electronSocket.emit('dock-getMenu-completed', menu);
});
socket.on('dock-setIcon', (image) => {
app.dock.setIcon(image);
});
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); };
}
});
}
};