diff options
Diffstat (limited to 'src/webview/notifications.js')
-rw-r--r-- | src/webview/notifications.js | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/src/webview/notifications.js b/src/webview/notifications.js deleted file mode 100644 index 22960d818..000000000 --- a/src/webview/notifications.js +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | import { ipcRenderer } from 'electron'; | ||
2 | |||
3 | import { v1 as uuidV1 } from 'uuid'; | ||
4 | |||
5 | const debug = require('debug')('Ferdi:Notifications'); | ||
6 | |||
7 | export class NotificationsHandler { | ||
8 | onNotify = data => data; | ||
9 | |||
10 | displayNotification(title, options) { | ||
11 | return new Promise(resolve => { | ||
12 | debug('New notification', title, options); | ||
13 | |||
14 | const notificationId = uuidV1(); | ||
15 | |||
16 | ipcRenderer.sendToHost( | ||
17 | 'notification', | ||
18 | this.onNotify({ | ||
19 | title, | ||
20 | options, | ||
21 | notificationId, | ||
22 | }), | ||
23 | ); | ||
24 | |||
25 | ipcRenderer.once(`notification-onclick:${notificationId}`, () => { | ||
26 | resolve(); | ||
27 | }); | ||
28 | }); | ||
29 | } | ||
30 | } | ||
31 | |||
32 | export const notificationsClassDefinition = `(() => { | ||
33 | class Notification { | ||
34 | static permission = 'granted'; | ||
35 | |||
36 | constructor(title = '', options = {}) { | ||
37 | this.title = title; | ||
38 | this.options = options; | ||
39 | window.ferdi.displayNotification(title, options) | ||
40 | .then(() => { | ||
41 | if (typeof (this.onClick) === 'function') { | ||
42 | this.onClick(); | ||
43 | } | ||
44 | }); | ||
45 | } | ||
46 | |||
47 | static requestPermission(cb = null) { | ||
48 | if (!cb) { | ||
49 | return new Promise((resolve) => { | ||
50 | resolve(Notification.permission); | ||
51 | }); | ||
52 | } | ||
53 | |||
54 | if (typeof (cb) === 'function') { | ||
55 | return cb(Notification.permission); | ||
56 | } | ||
57 | |||
58 | return Notification.permission; | ||
59 | } | ||
60 | |||
61 | onNotify(data) { | ||
62 | return data; | ||
63 | } | ||
64 | |||
65 | onClick() {} | ||
66 | |||
67 | close() {} | ||
68 | } | ||
69 | |||
70 | window.Notification = Notification; | ||
71 | })();`; | ||