From c92c8256b18ff8b4ca0cd0b68e30c6d88c6a4fa5 Mon Sep 17 00:00:00 2001 From: Nicolas Mowen Date: Sat, 20 Jul 2024 15:36:11 -0600 Subject: [PATCH] Always open notification --- frigate/comms/webpush.py | 4 ++-- web/public/notifications-worker.js | 19 +++---------------- 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/frigate/comms/webpush.py b/frigate/comms/webpush.py index 273805f69..2320692b3 100644 --- a/frigate/comms/webpush.py +++ b/frigate/comms/webpush.py @@ -90,7 +90,7 @@ class WebPushClient(Communicator): # type: ignore[misc] title = f"{', '.join(sorted_objects).replace('_', ' ').title()}{' was' if state == 'end' else ''} detected in {', '.join(payload['after']['data']['zones']).replace('_', ' ').title()}" message = f"Detected on {payload['after']['camera'].replace('_', ' ').title()}" - link = f"/review?id={reviewId}" + direct_url = f"/review?id={reviewId}" image = f'{payload["after"]["thumb_path"].replace("/media/frigate", "")}' for pusher in self.web_pushers: @@ -101,7 +101,7 @@ class WebPushClient(Communicator): # type: ignore[misc] { "title": title, "message": message, - "link": link, + "direct_url": direct_url, "image": image, "id": reviewId, } diff --git a/web/public/notifications-worker.js b/web/public/notifications-worker.js index 7bf0ab248..5e0e2a0f8 100644 --- a/web/public/notifications-worker.js +++ b/web/public/notifications-worker.js @@ -29,24 +29,11 @@ self.addEventListener("notificationclick", (event) => { // @ts-expect-error we know this exists if (event.notification.data) { const url = event.notification.data.link; - // eslint-disable-next-line no-undef - clients.matchAll({ type: "window" }).then((windowClients) => { - // Check if there is already a window/tab open with the target URL - for (let i = 0; i < windowClients.length; i++) { - const client = windowClients[i]; - // If so, just focus it. - if (client.url === url && "focus" in client) { - return client.focus(); - } - } - // If not, then open the target URL in a new window/tab. + if (clients.openWindow) { // eslint-disable-next-line no-undef - if (clients.openWindow) { - // eslint-disable-next-line no-undef - return clients.openWindow(url); - } - }); + return clients.openWindow(url); + } } } });