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