From a62b29955da3c028953ee68ae1673dd86769267d Mon Sep 17 00:00:00 2001 From: Cyperghost Date: Thu, 15 Feb 2024 12:21:19 +0100 Subject: [PATCH] Rename link to url Add `notificationclick` event to open new window with the given url --- ts/WoltLabSuite/Core/Notification/ServiceWorker.ts | 1 - .../js/WoltLabSuite/Core/Notification/ServiceWorker.js | 1 - wcfsetup/install/files/js/serviceWorker.js | 8 +++++++- .../job/ServiceWorkerDeliveryBackgroundJob.class.php | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ts/WoltLabSuite/Core/Notification/ServiceWorker.ts b/ts/WoltLabSuite/Core/Notification/ServiceWorker.ts index ea3274b91d..1ea5a43554 100644 --- a/ts/WoltLabSuite/Core/Notification/ServiceWorker.ts +++ b/ts/WoltLabSuite/Core/Notification/ServiceWorker.ts @@ -17,7 +17,6 @@ class ServiceWorker { this.publicKey = publicKey; this.serviceWorkerJsUrl = serviceWorkerJsUrl; this.registerUrl = registerUrl; - // TODO check if service worker is already registered } async register(): Promise { diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/ServiceWorker.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/ServiceWorker.js index 5549752fad..79f275cd9e 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/ServiceWorker.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Notification/ServiceWorker.js @@ -17,7 +17,6 @@ define(["require", "exports", "WoltLabSuite/Core/Ajax/Backend"], function (requi this.publicKey = publicKey; this.serviceWorkerJsUrl = serviceWorkerJsUrl; this.registerUrl = registerUrl; - // TODO check if service worker is already registered } async register() { try { diff --git a/wcfsetup/install/files/js/serviceWorker.js b/wcfsetup/install/files/js/serviceWorker.js index 5fc28a5525..250e444cf7 100644 --- a/wcfsetup/install/files/js/serviceWorker.js +++ b/wcfsetup/install/files/js/serviceWorker.js @@ -32,9 +32,15 @@ self.addEventListener("push", async (event) => { timestamp: payload.time, tag: payload.notificationID, data: { - link: payload.link, + url: payload.url, time: payload.time, }, }), ); }); + +self.addEventListener("notificationclick", (event) => { + event.notification.close(); + + event.waitUntil(clients.openWindow(event.notification.data.url)); +}); diff --git a/wcfsetup/install/files/lib/system/background/job/ServiceWorkerDeliveryBackgroundJob.class.php b/wcfsetup/install/files/lib/system/background/job/ServiceWorkerDeliveryBackgroundJob.class.php index 33cab0b685..9a6eafd094 100644 --- a/wcfsetup/install/files/lib/system/background/job/ServiceWorkerDeliveryBackgroundJob.class.php +++ b/wcfsetup/install/files/lib/system/background/job/ServiceWorkerDeliveryBackgroundJob.class.php @@ -36,7 +36,7 @@ final class ServiceWorkerDeliveryBackgroundJob extends AbstractBackgroundJob public function perform() { $serviceWorker = new ServiceWorker($this->serviceWorkerID); - if ($serviceWorker->workerID) { + if (!$serviceWorker->workerID) { // Service worker no longer exists return; } @@ -79,7 +79,7 @@ final class ServiceWorkerDeliveryBackgroundJob extends AbstractBackgroundJob $content = [ "title" => $event->getTitle(), "message" => StringUtil::stripHTML($event->getMessage()), - "link" => $event->getLink(), + "url" => $event->getLink(), "notificationID" => $notification->notificationID, "time" => $notification->time, "icon" => $style->getFaviconAppleTouchIcon(), -- 2.20.1