Files
Electron.NET/ElectronNET.Host/api/notification.ts

58 lines
1.8 KiB
TypeScript
Raw Normal View History

2019-01-04 03:27:12 +01:00
import { Notification } from 'electron';
const notifications: Electron.Notification[] = (global['notifications'] = global['notifications'] || []) as Electron.Notification[];
let electronSocket;
2018-09-26 01:31:53 +02:00
export = (socket: SocketIO.Socket) => {
electronSocket = socket;
socket.on('createNotification', (options) => {
const notification = new Notification(options);
2017-10-18 03:49:34 +02:00
let haveEvent = false;
2019-01-04 03:27:12 +01:00
if (options.showID) {
2017-10-18 03:49:34 +02:00
haveEvent = true;
notification.on('show', () => {
electronSocket.emit('NotificationEventShow', options.showID);
2017-10-18 03:49:34 +02:00
});
}
2019-01-04 03:27:12 +01:00
if (options.clickID) {
2017-10-18 03:49:34 +02:00
haveEvent = true;
notification.on('click', () => {
electronSocket.emit('NotificationEventClick', options.clickID);
2017-10-18 03:49:34 +02:00
});
}
2019-01-04 03:27:12 +01:00
if (options.closeID) {
2017-10-18 03:49:34 +02:00
haveEvent = true;
notification.on('close', () => {
electronSocket.emit('NotificationEventClose', options.closeID);
2017-10-18 03:49:34 +02:00
});
}
2019-01-04 03:27:12 +01:00
if (options.replyID) {
2017-10-18 03:49:34 +02:00
haveEvent = true;
notification.on('reply', (event, value) => {
electronSocket.emit('NotificationEventReply', [options.replyID, value]);
2017-10-18 03:49:34 +02:00
});
}
2019-01-04 03:27:12 +01:00
if (options.actionID) {
2017-10-18 03:49:34 +02:00
haveEvent = true;
notification.on('action', (event, value) => {
electronSocket.emit('NotificationEventAction', [options.actionID, value]);
2017-10-18 03:49:34 +02:00
});
}
2019-01-04 03:27:12 +01:00
if (haveEvent) {
2017-10-18 03:49:34 +02:00
notifications.push(notification);
}
notification.show();
});
2017-10-18 03:49:34 +02:00
socket.on('notificationIsSupported', () => {
2017-10-18 03:49:34 +02:00
const isSupported = Notification.isSupported;
electronSocket.emit('notificationIsSupportedComplete', isSupported);
2017-10-18 03:49:34 +02:00
});
2019-01-04 03:27:12 +01:00
};