fix(ui): improve visibility condition and push notification handling (#199)

Resolve visibility state for beacon reporting to handle focus correctly
Normalize push subscriptions per UI session and send to each endpoint
Suppress push notifications when a visible window exists to avoid redundant alerts
This commit is contained in:
Bohdan Triapitsyn
2026-01-23 01:51:22 +02:00
committed by GitHub
parent 51922d7b23
commit 71b9ec6e3d
3 changed files with 77 additions and 75 deletions
+18 -12
View File
@@ -34,25 +34,31 @@ self.addEventListener('activate', (event) => {
});
self.addEventListener('push', (event) => {
const payload = (event.data?.json() ?? null) as PushPayload | null;
if (!payload) {
return;
}
event.waitUntil((async () => {
const payload = (event.data?.json() ?? null) as PushPayload | null;
if (!payload) {
return;
}
const title = payload.title || 'OpenChamber';
const body = payload.body ?? '';
const icon = payload.icon ?? '/apple-touch-icon-180x180.png';
const badge = payload.badge ?? '/favicon-32.png';
const clients = await self.clients.matchAll({ type: 'window', includeUncontrolled: true });
const hasVisibleClient = clients.some((client) => client.visibilityState === 'visible' || client.focused);
if (hasVisibleClient) {
return;
}
event.waitUntil(
self.registration.showNotification(title, {
const title = payload.title || 'OpenChamber';
const body = payload.body ?? '';
const icon = payload.icon ?? '/apple-touch-icon-180x180.png';
const badge = payload.badge ?? '/favicon-32.png';
await self.registration.showNotification(title, {
body,
icon,
badge,
tag: payload.tag,
data: payload.data,
})
);
});
})());
});
self.addEventListener('notificationclick', (event) => {