fix(app): improve service worker notification handling (#6)

This commit is contained in:
hampus-fluxer
2026-01-03 08:21:02 +01:00
committed by GitHub
parent 4cd1caaa80
commit 5d5815963c
3 changed files with 174 additions and 42 deletions

View File

@@ -130,12 +130,25 @@ const focusOrOpenClient = async (targetUrl: string, targetUserId?: string): Prom
if (targetUserId) {
message.targetUserId = targetUserId;
}
const clientList = await postMessageToClients(message);
for (const client of clientList) {
if (client.url === targetUrl) {
await client.focus();
return;
const exact = clientList.find((c) => c.url === targetUrl);
if (exact) {
await exact.focus();
return;
}
const sameOrigin = clientList.find((c) => {
try {
return new URL(c.url).origin === self.location.origin;
} catch {
return false;
}
});
if (sameOrigin) {
await sameOrigin.focus();
return;
}
if (self.clients.openWindow) {