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