Skip to content

Commit

Permalink
Always open notification
Browse files Browse the repository at this point in the history
  • Loading branch information
NickM-27 committed Jul 21, 2024
1 parent 367555b commit c92c825
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 18 deletions.
4 changes: 2 additions & 2 deletions frigate/comms/webpush.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def send_message(self, payload: dict[str, any]) -> None:

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:
Expand All @@ -101,7 +101,7 @@ def send_message(self, payload: dict[str, any]) -> None:
{
"title": title,
"message": message,
"link": link,
"direct_url": direct_url,
"image": image,
"id": reviewId,
}
Expand Down
19 changes: 3 additions & 16 deletions web/public/notifications-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
});

0 comments on commit c92c825

Please sign in to comment.