diff options
author | 2021-08-13 00:45:01 +0530 | |
---|---|---|
committer | 2021-08-13 00:45:01 +0530 | |
commit | 2d27d5e66649d4f5baf127a53ee5ae524eae3a59 (patch) | |
tree | c592ea219ac8cd987fc367f57b54034c450ab2ab /src/webview/notifications.js | |
parent | Ferdi v5.6.0 (diff) | |
parent | 5.6.1-nightly.24 [skip ci] (diff) | |
download | ferdium-app-2d27d5e66649d4f5baf127a53ee5ae524eae3a59.tar.gz ferdium-app-2d27d5e66649d4f5baf127a53ee5ae524eae3a59.tar.zst ferdium-app-2d27d5e66649d4f5baf127a53ee5ae524eae3a59.zip |
chore: merge from nightly branch into release branch in prep for next beta
Diffstat (limited to 'src/webview/notifications.js')
-rw-r--r-- | src/webview/notifications.js | 88 |
1 files changed, 52 insertions, 36 deletions
diff --git a/src/webview/notifications.js b/src/webview/notifications.js index 021f05cc3..205a3220c 100644 --- a/src/webview/notifications.js +++ b/src/webview/notifications.js | |||
@@ -3,49 +3,65 @@ import uuidV1 from 'uuid/v1'; | |||
3 | 3 | ||
4 | const debug = require('debug')('Ferdi:Notifications'); | 4 | const debug = require('debug')('Ferdi:Notifications'); |
5 | 5 | ||
6 | class Notification { | 6 | export 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) { | 28 | export 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 | ||
51 | window.Notification = Notification; | 66 | window.Notification = Notification; |
67 | })();`; | ||