aboutsummaryrefslogtreecommitdiffstats
path: root/src/webview/notifications.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/webview/notifications.ts')
-rw-r--r--src/webview/notifications.ts59
1 files changed, 18 insertions, 41 deletions
diff --git a/src/webview/notifications.ts b/src/webview/notifications.ts
index e4401ab6e..835869f5c 100644
--- a/src/webview/notifications.ts
+++ b/src/webview/notifications.ts
@@ -31,52 +31,29 @@ export class NotificationsHandler {
31} 31}
32 32
33export const notificationsClassDefinition = `(() => { 33export const notificationsClassDefinition = `(() => {
34 class Notification { 34class Notification {
35 static permission = 'granted'; 35 static permission = 'granted';
36 36
37 constructor(title = '', options = {}) { 37 constructor(title = '', options = {}) {
38 this.title = title; 38 window.ferdium.displayNotification(title, options).then(() => {
39 this.options = options; 39 // TODO: After several tries, we couldn't find a way to trigger the native notification onclick event.
40 try { 40 // This was needed so that user could go to the specific context when clicking on the notification (it only goes to the service now).
41 window.ferdium.displayNotification(title, options) 41 // For now, we don't do anything here
42 .then(() => { 42 });
43 if (typeof (this.onClick) === 'function') { 43 }
44 this.onClick();
45 }
46 });
47 } catch(error) {
48 this.options.onClick = null;
49 window.ferdium.displayNotification(title, options)
50 .then(() => {
51 if (typeof (this.onClick) === 'function') {
52 this.onClick();
53 }
54 });
55 }
56 }
57
58 static requestPermission(cb = null) {
59 if (!cb) {
60 return new Promise((resolve) => {
61 resolve(Notification.permission);
62 });
63 }
64
65 if (typeof (cb) === 'function') {
66 return cb(Notification.permission);
67 }
68
69 return Notification.permission;
70 }
71 44
72 onNotify(data) { 45 static requestPermission(cb) {
73 return data; 46 if (typeof cb === 'function') {
47 cb(Notification.permission);
74 } 48 }
75 49
76 onClick() {} 50 return Promise.resolve(Notification.permission);
51 }
77 52
78 close() {} 53 onNotify(data) {
54 return data;
79 } 55 }
56}
80 57
81 window.Notification = Notification; 58 window.Notification = Notification;
82})();`; 59})();`;