Always open notification

This commit is contained in:
Nicolas Mowen 2024-07-20 15:36:11 -06:00
parent 367555ba98
commit c92c8256b1
2 changed files with 5 additions and 18 deletions

View File

@ -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()}" 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()}" 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", "")}' image = f'{payload["after"]["thumb_path"].replace("/media/frigate", "")}'
for pusher in self.web_pushers: for pusher in self.web_pushers:
@ -101,7 +101,7 @@ class WebPushClient(Communicator): # type: ignore[misc]
{ {
"title": title, "title": title,
"message": message, "message": message,
"link": link, "direct_url": direct_url,
"image": image, "image": image,
"id": reviewId, "id": reviewId,
} }

View File

@ -29,24 +29,11 @@ self.addEventListener("notificationclick", (event) => {
// @ts-expect-error we know this exists // @ts-expect-error we know this exists
if (event.notification.data) { if (event.notification.data) {
const url = event.notification.data.link; const url = event.notification.data.link;
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
clients.matchAll({ type: "window" }).then((windowClients) => { if (clients.openWindow) {
// 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.
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
if (clients.openWindow) { return clients.openWindow(url);
// eslint-disable-next-line no-undef }
return clients.openWindow(url);
}
});
} }
} }
}); });