Web Push Zustand und Deep Links stabilisieren
All checks were successful
CI / Build and Deploy (push) Successful in 2m59s

This commit is contained in:
jan
2026-05-06 21:13:54 +02:00
parent 0d72cfb144
commit 3e5ac7730d
5 changed files with 123 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
const CACHE_NAME = "rave-budget-control-v1";
const CACHE_NAME = "rave-budget-control-v2";
const APP_SHELL = ["/", "/login", "/icon.svg", "/manifest.webmanifest"];
self.addEventListener("install", (event) => {
@@ -14,7 +14,7 @@ self.addEventListener("activate", (event) => {
event.waitUntil(
caches.keys().then((cacheNames) =>
Promise.all(cacheNames.filter((cacheName) => cacheName !== CACHE_NAME).map((cacheName) => caches.delete(cacheName)))
)
).then(() => self.clients.claim())
);
});
@@ -66,10 +66,24 @@ self.addEventListener("notificationclick", (event) => {
event.waitUntil(
clients.matchAll({ type: "window", includeUncontrolled: true }).then(async (clientList) => {
for (const client of clientList) {
const sameOriginClients = clientList.filter((client) => {
const clientUrl = new URL(client.url);
return clientUrl.origin === targetUrl.origin;
});
if (clientUrl.origin === targetUrl.origin && "focus" in client) {
const exactClient = sameOriginClients.find((client) => new URL(client.url).href === targetUrl.href);
const targetClient = exactClient ?? sameOriginClients[0];
if (targetClient && "focus" in targetClient) {
if ("navigate" in targetClient && new URL(targetClient.url).href !== targetUrl.href) {
await targetClient.navigate(targetUrl.href).catch(() => null);
}
return targetClient.focus();
}
for (const client of sameOriginClients) {
if ("focus" in client) {
if ("navigate" in client) {
await client.navigate(targetUrl.href).catch(() => null);
}