mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-03-25 09:38:22 +03:00
Notification Fixes (#22599)
* Fix iOS having notification token revoked * Try to handle iOS stacked notifications * Fix typo * Improve updating of notification script
This commit is contained in:
parent
573a5ede62
commit
d27ee166bc
@ -19,8 +19,7 @@ self.addEventListener("push", function (event) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-expect-error we know this exists
|
const notificationOptions = {
|
||||||
self.registration.showNotification(data.title, {
|
|
||||||
body: data.message,
|
body: data.message,
|
||||||
icon: "/images/maskable-icon.png",
|
icon: "/images/maskable-icon.png",
|
||||||
image: data.image,
|
image: data.image,
|
||||||
@ -28,7 +27,33 @@ self.addEventListener("push", function (event) {
|
|||||||
tag: data.id,
|
tag: data.id,
|
||||||
data: { id: data.id, link: data.direct_url },
|
data: { id: data.id, link: data.direct_url },
|
||||||
actions,
|
actions,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
// iOS Safari does not auto-coalesce notifications by tag (WebKit bug #258922).
|
||||||
|
// On iOS 18.3+ close() works, so we manually close duplicates before showing.
|
||||||
|
// On other platforms, tag-based replacement works natively — skip the extra work.
|
||||||
|
const isIOS =
|
||||||
|
/iPad|iPhone|iPod/.test(navigator.userAgent) && !self.MSStream;
|
||||||
|
|
||||||
|
const show = () =>
|
||||||
|
// @ts-expect-error we know this exists
|
||||||
|
self.registration.showNotification(data.title, notificationOptions);
|
||||||
|
|
||||||
|
// event.waitUntil is required on iOS Safari — without it, the browser
|
||||||
|
// may consider this a "silent push" and revoke the subscription after 3 occurrences.
|
||||||
|
event.waitUntil(
|
||||||
|
isIOS
|
||||||
|
? // @ts-expect-error we know this exists
|
||||||
|
self.registration
|
||||||
|
.getNotifications({ tag: data.id })
|
||||||
|
.then((existing) => {
|
||||||
|
for (const n of existing) {
|
||||||
|
n.close();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(show)
|
||||||
|
: show(), // eslint-disable-line comma-dangle
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
// pass
|
// pass
|
||||||
// This push event has no data
|
// This push event has no data
|
||||||
|
|||||||
@ -58,7 +58,7 @@ import type { ConfigSectionData, JsonObject } from "@/types/configForm";
|
|||||||
import { sanitizeSectionData } from "@/utils/configUtil";
|
import { sanitizeSectionData } from "@/utils/configUtil";
|
||||||
import type { SectionRendererProps } from "./registry";
|
import type { SectionRendererProps } from "./registry";
|
||||||
|
|
||||||
const NOTIFICATION_SERVICE_WORKER = "/notification-worker.js";
|
const NOTIFICATION_SERVICE_WORKER = "/notifications-worker.js";
|
||||||
import {
|
import {
|
||||||
SettingsGroupCard,
|
SettingsGroupCard,
|
||||||
SPLIT_ROW_CLASS_NAME,
|
SPLIT_ROW_CLASS_NAME,
|
||||||
@ -126,6 +126,8 @@ export default function NotificationsSettingsExtras({
|
|||||||
.getRegistration(NOTIFICATION_SERVICE_WORKER)
|
.getRegistration(NOTIFICATION_SERVICE_WORKER)
|
||||||
.then((worker) => {
|
.then((worker) => {
|
||||||
if (worker) {
|
if (worker) {
|
||||||
|
// Trigger a check for an updated service worker script
|
||||||
|
worker.update().catch(() => {});
|
||||||
setRegistration(worker);
|
setRegistration(worker);
|
||||||
} else {
|
} else {
|
||||||
setRegistration(null);
|
setRegistration(null);
|
||||||
@ -633,7 +635,9 @@ export default function NotificationsSettingsExtras({
|
|||||||
Notification.requestPermission().then((permission) => {
|
Notification.requestPermission().then((permission) => {
|
||||||
if (permission === "granted") {
|
if (permission === "granted") {
|
||||||
navigator.serviceWorker
|
navigator.serviceWorker
|
||||||
.register(NOTIFICATION_SERVICE_WORKER)
|
.register(NOTIFICATION_SERVICE_WORKER, {
|
||||||
|
updateViaCache: "none",
|
||||||
|
})
|
||||||
.then((workerRegistration) => {
|
.then((workerRegistration) => {
|
||||||
setRegistration(workerRegistration);
|
setRegistration(workerRegistration);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user