2017-10-15 17:03:07 +02:00
|
|
|
"use strict";
|
2021-01-12 03:12:01 +01:00
|
|
|
const electron_1 = require("electron");
|
|
|
|
|
const notifications = (global['notifications'] = global['notifications'] || []);
|
|
|
|
|
let electronSocket;
|
|
|
|
|
module.exports = (socket) => {
|
2019-04-18 18:03:17 +01:00
|
|
|
electronSocket = socket;
|
2021-01-12 03:12:01 +01:00
|
|
|
socket.on('createNotification', (options) => {
|
|
|
|
|
const notification = new electron_1.Notification(options);
|
|
|
|
|
let haveEvent = false;
|
2017-10-18 03:49:34 +02:00
|
|
|
if (options.showID) {
|
|
|
|
|
haveEvent = true;
|
2021-01-12 03:12:01 +01:00
|
|
|
notification.on('show', () => {
|
2019-04-18 18:03:17 +01:00
|
|
|
electronSocket.emit('NotificationEventShow', options.showID);
|
2017-10-18 03:49:34 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (options.clickID) {
|
|
|
|
|
haveEvent = true;
|
2021-01-12 03:12:01 +01:00
|
|
|
notification.on('click', () => {
|
2019-04-18 18:03:17 +01:00
|
|
|
electronSocket.emit('NotificationEventClick', options.clickID);
|
2017-10-18 03:49:34 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (options.closeID) {
|
|
|
|
|
haveEvent = true;
|
2021-01-12 03:12:01 +01:00
|
|
|
notification.on('close', () => {
|
2019-04-18 18:03:17 +01:00
|
|
|
electronSocket.emit('NotificationEventClose', options.closeID);
|
2017-10-18 03:49:34 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (options.replyID) {
|
|
|
|
|
haveEvent = true;
|
2021-01-12 03:12:01 +01:00
|
|
|
notification.on('reply', (event, value) => {
|
2019-04-18 18:03:17 +01:00
|
|
|
electronSocket.emit('NotificationEventReply', [options.replyID, value]);
|
2017-10-18 03:49:34 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (options.actionID) {
|
|
|
|
|
haveEvent = true;
|
2021-01-12 03:12:01 +01:00
|
|
|
notification.on('action', (event, value) => {
|
2019-04-18 18:03:17 +01:00
|
|
|
electronSocket.emit('NotificationEventAction', [options.actionID, value]);
|
2017-10-18 03:49:34 +02:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (haveEvent) {
|
|
|
|
|
notifications.push(notification);
|
|
|
|
|
}
|
2017-10-15 17:03:07 +02:00
|
|
|
notification.show();
|
|
|
|
|
});
|
2021-01-12 03:12:01 +01:00
|
|
|
socket.on('notificationIsSupported', () => {
|
|
|
|
|
const isSupported = electron_1.Notification.isSupported;
|
2019-04-18 18:03:17 +01:00
|
|
|
electronSocket.emit('notificationIsSupportedComplete', isSupported);
|
2017-10-18 03:49:34 +02:00
|
|
|
});
|
2017-10-15 17:03:07 +02:00
|
|
|
};
|
2021-01-12 03:12:01 +01:00
|
|
|
//# sourceMappingURL=notification.js.map
|