From 793d4db6d0ddba721b3a7877e471e6cf647956e7 Mon Sep 17 00:00:00 2001 From: Andreas Creten Date: Wed, 19 Feb 2025 15:54:37 +0100 Subject: [PATCH 1/2] Expand notification api with reference and more events --- .../src/server/api/notification.ts | 46 +++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/resources/js/electron-plugin/src/server/api/notification.ts b/resources/js/electron-plugin/src/server/api/notification.ts index 70817c4c..0f5e467d 100644 --- a/resources/js/electron-plugin/src/server/api/notification.ts +++ b/resources/js/electron-plugin/src/server/api/notification.ts @@ -18,11 +18,14 @@ router.post('/', (req, res) => { actions, closeButtonText, toastXml, - event: customEvent + event: customEvent, + reference, } = req.body; const eventName = customEvent ?? '\\Native\\Laravel\\Events\\Notifications\\NotificationClicked'; + const notificationReference = reference ?? Date.now(); + const notification = new Notification({ title, body, @@ -42,13 +45,50 @@ router.post('/', (req, res) => { notification.on("click", (event) => { notifyLaravel('events', { event: eventName, - payload: JSON.stringify(event) + payload: { + reference: notificationReference, + event: JSON.stringify(event), + }, + }); + }); + + notification.on("action", (event, index) => { + notifyLaravel('events', { + event: '\\Native\\Laravel\\Events\\Notifications\\NotificationActionClicked', + payload: { + reference: notificationReference, + index, + event: JSON.stringify(event), + }, + }); + }); + + notification.on("reply", (event, reply) => { + notifyLaravel('events', { + event: '\\Native\\Laravel\\Events\\Notifications\\NotificationReply', + payload: { + reference: notificationReference, + reply, + event: JSON.stringify(event), + }, + }); + }); + + notification.on("close", (event) => { + notifyLaravel('events', { + event: '\\Native\\Laravel\\Events\\Notifications\\NotificationClosed', + payload: { + reference: notificationReference, + event: JSON.stringify(event), + }, }); }); notification.show(); - res.sendStatus(200); + res.status(200).json({ + reference: notificationReference, + }); }); export default router; From 315b6bf15d57748679659a2b4e4e4b9e6451f2b1 Mon Sep 17 00:00:00 2001 From: Andreas Creten Date: Fri, 21 Feb 2025 14:38:38 +0100 Subject: [PATCH 2/2] Ensure unique identifier --- resources/js/electron-plugin/src/server/api/notification.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/js/electron-plugin/src/server/api/notification.ts b/resources/js/electron-plugin/src/server/api/notification.ts index b0450aef..7f481f5c 100644 --- a/resources/js/electron-plugin/src/server/api/notification.ts +++ b/resources/js/electron-plugin/src/server/api/notification.ts @@ -24,7 +24,7 @@ router.post('/', (req, res) => { const eventName = customEvent ?? '\\Native\\Laravel\\Events\\Notifications\\NotificationClicked'; - const notificationReference = reference ?? Date.now(); + const notificationReference = reference ?? (Date.now() + '.' + Math.random().toString(36).slice(2, 9)); const notification = new Notification({ title,