diff options
author | André Oliveira <37463445+SpecialAro@users.noreply.github.com> | 2024-05-13 22:31:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-13 22:31:23 +0100 |
commit | 0ed2bacd83a05ce3190bfa7124a04a0de6abf9fc (patch) | |
tree | 462821dd34526fd889365b81f5e1d990c85e4257 /src | |
parent | 6.7.4-nightly.9 [skip ci] (diff) | |
download | ferdium-app-0ed2bacd83a05ce3190bfa7124a04a0de6abf9fc.tar.gz ferdium-app-0ed2bacd83a05ce3190bfa7124a04a0de6abf9fc.tar.zst ferdium-app-0ed2bacd83a05ce3190bfa7124a04a0de6abf9fc.zip |
Fix notifications on all services (#1593)
* refactor class
* Revert "refactor class"
This reverts commit 7e266d7aa4905f236457c44f9ffc37fa8f742b4c.
* refactor: change logic
* Working logic (but double notifications)
* fix: final adjustments
Diffstat (limited to 'src')
-rw-r--r-- | src/stores/ServicesStore.ts | 3 | ||||
-rw-r--r-- | src/webview/notifications.ts | 59 | ||||
-rw-r--r-- | src/webview/recipe.ts | 2 |
3 files changed, 21 insertions, 43 deletions
diff --git a/src/stores/ServicesStore.ts b/src/stores/ServicesStore.ts index 9f2cfeca3..58c6b2a87 100644 --- a/src/stores/ServicesStore.ts +++ b/src/stores/ServicesStore.ts | |||
@@ -917,12 +917,13 @@ export default class ServicesStore extends TypedStore { | |||
917 | 917 | ||
918 | if (service.isNotificationEnabled) { | 918 | if (service.isNotificationEnabled) { |
919 | let title: string; | 919 | let title: string; |
920 | options.icon = service.iconUrl; | ||
921 | if (this.stores.settings.all.app.privateNotifications === true) { | 920 | if (this.stores.settings.all.app.privateNotifications === true) { |
922 | // Remove message data from notification in private mode | 921 | // Remove message data from notification in private mode |
923 | options.body = ''; | 922 | options.body = ''; |
923 | options.icon = service.icon; | ||
924 | title = `Notification from ${service.name}`; | 924 | title = `Notification from ${service.name}`; |
925 | } else { | 925 | } else { |
926 | options.icon = options.icon || service.icon; | ||
926 | options.body = typeof options.body === 'string' ? options.body : ''; | 927 | options.body = typeof options.body === 'string' ? options.body : ''; |
927 | title = | 928 | title = |
928 | typeof args[0].title === 'string' ? args[0].title : service.name; | 929 | typeof args[0].title === 'string' ? args[0].title : service.name; |
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 | ||
33 | export const notificationsClassDefinition = `(() => { | 33 | export const notificationsClassDefinition = `(() => { |
34 | class Notification { | 34 | class 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 | })();`; |
diff --git a/src/webview/recipe.ts b/src/webview/recipe.ts index a35a99699..ad2215ffd 100644 --- a/src/webview/recipe.ts +++ b/src/webview/recipe.ts | |||
@@ -121,7 +121,7 @@ contextBridge.exposeInMainWorld('ferdium', { | |||
121 | setDialogTitle: (title: string | null | undefined) => | 121 | setDialogTitle: (title: string | null | undefined) => |
122 | dialogTitleHandler.setDialogTitle(title), | 122 | dialogTitleHandler.setDialogTitle(title), |
123 | displayNotification: (title: string, options: any) => { | 123 | displayNotification: (title: string, options: any) => { |
124 | notificationsHandler.displayNotification( | 124 | return notificationsHandler.displayNotification( |
125 | title, | 125 | title, |
126 | // The following line is needed so that a proper clone of the "options" object is made. | 126 | // The following line is needed so that a proper clone of the "options" object is made. |
127 | // This line was causing issues with some services. | 127 | // This line was causing issues with some services. |