Web Push Zustand und Deep Links stabilisieren
All checks were successful
CI / Build and Deploy (push) Successful in 2m59s
All checks were successful
CI / Build and Deploy (push) Successful in 2m59s
This commit is contained in:
22
public/sw.js
22
public/sw.js
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user