This commit is contained in:
2026-03-23 08:14:02 -04:00
parent 2d164958d8
commit 14c80f436a
4 changed files with 92 additions and 33 deletions

View File

@@ -54,6 +54,7 @@ self.addEventListener('fetch', (event) => {
let badgeCount = 0;
function showRosterChirpNotification(data) {
console.log('[SW] showRosterChirpNotification:', JSON.stringify(data));
badgeCount++;
if (self.navigator?.setAppBadge) self.navigator.setAppBadge(badgeCount).catch(() => {});
@@ -64,17 +65,29 @@ function showRosterChirpNotification(data) {
data: { url: data.url || '/' },
tag: data.groupId ? `rosterchirp-group-${data.groupId}` : 'rosterchirp-message',
renotify: true,
vibrate: [200, 100, 200], // haptic pattern — also activates the OS sound channel
vibrate: [200, 100, 200],
});
}
// ── FCM background messages ───────────────────────────────────────────────────
if (messaging) {
messaging.onBackgroundMessage((payload) => {
console.log('[SW] onBackgroundMessage received, data:', JSON.stringify(payload.data));
return showRosterChirpNotification(payload.data || {});
});
} else {
console.warn('[SW] Firebase messaging not initialised — push notifications disabled');
}
// ── Raw push event (fallback diagnostic) ─────────────────────────────────────
// Fires for every push event BEFORE the Firebase SDK handles it.
// Log it so chrome://inspect shows whether the SW is even waking up.
self.addEventListener('push', (event) => {
console.log('[SW] push event received, hasData:', !!event.data, 'text:', event.data?.text?.()?.slice(0, 120));
// Note: Firebase compat SDK registers its own push listener and handles display.
// This listener is diagnostic only — do not call showNotification() here.
});
// ── Notification click ────────────────────────────────────────────────────────
self.addEventListener('notificationclick', (event) => {
event.notification.close();