-
-
Notifications
You must be signed in to change notification settings - Fork 748
Expand file tree
/
Copy pathnotification.ts
More file actions
64 lines (53 loc) · 1.64 KB
/
notification.ts
File metadata and controls
64 lines (53 loc) · 1.64 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
import type { Socket } from "net";
import { Notification } from "electron";
const notifications: Electron.Notification[] = (global["notifications"] =
global["notifications"] || []) as Electron.Notification[];
let electronSocket: Socket;
export = (socket: Socket) => {
electronSocket = socket;
socket.on("createNotification", (options) => {
const notification = new Notification(options);
let haveEvent = false;
if (options.showID) {
haveEvent = true;
notification.on("show", () => {
electronSocket.emit("NotificationEventShow", options.showID);
});
}
if (options.clickID) {
haveEvent = true;
notification.on("click", () => {
electronSocket.emit("NotificationEventClick", options.clickID);
});
}
if (options.closeID) {
haveEvent = true;
notification.on("close", () => {
electronSocket.emit("NotificationEventClose", options.closeID);
});
}
if (options.replyID) {
haveEvent = true;
notification.on("reply", (event, value) => {
electronSocket.emit("NotificationEventReply", [options.replyID, value]);
});
}
if (options.actionID) {
haveEvent = true;
notification.on("action", (event, value) => {
electronSocket.emit("NotificationEventAction", [
options.actionID,
value,
]);
});
}
if (haveEvent) {
notifications.push(notification);
}
notification.show();
});
socket.on("notificationIsSupported", () => {
const isSupported = Notification.isSupported();
electronSocket.emit("notificationIsSupportedCompleted", isSupported);
});
};