-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathindex.js
More file actions
34 lines (29 loc) · 1002 Bytes
/
Copy pathindex.js
File metadata and controls
34 lines (29 loc) · 1002 Bytes
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
'use strict';
// Electron doesn't automatically show notifications in Windows yet, and it's not easy to polyfill.
// So we have to hijack the Notification API.
let ipc;
try {
// Using electron >=0.35
ipc = require('electron').ipcRenderer;
} catch (e) {
// Assume it's electron <0.35
ipc = require('ipc');
}
module.exports = () => {
const OldNotification = Notification;
Notification = function (title, options) {
// Send this to main thread.
// Catch it in your main 'app' instance with `ipc.on`.
// Then send it back to the view, if you want, with `event.returnValue` or `event.sender.send()`.
ipc.send('notification-shim', {
title,
options
});
// Send the native Notification.
// You can't catch it, that's why we're doing all of this. :)
return new OldNotification(title, options);
};
Notification.prototype = OldNotification.prototype;
Notification.permission = OldNotification.permission;
Notification.requestPermission = OldNotification.requestPermission;
};