Prevent firefox from crashing because of no badging API

This commit is contained in:
Gigiaj 2025-06-12 17:34:29 -05:00
parent 815a0ac7f4
commit f24c6cce76
3 changed files with 16 additions and 3 deletions

View file

@ -48,7 +48,11 @@ export const useRoomEventReaders = (room: Room, eventId?: string): string[] => {
room.on(RoomEvent.Receipt, handleReceipt); room.on(RoomEvent.Receipt, handleReceipt);
room.on(RoomEvent.LocalEchoUpdated, handleLocalEcho); room.on(RoomEvent.LocalEchoUpdated, handleLocalEcho);
navigator.setAppBadge(unreadInfo.total); try {
navigator.setAppBadge(unreadInfo.total);
} catch (e) {
// Likely Firefox/Gecko-based and doesn't support badging API
}
return () => { return () => {
room.removeListener(RoomEvent.Receipt, handleReceipt); room.removeListener(RoomEvent.Receipt, handleReceipt);
room.removeListener(RoomEvent.LocalEchoUpdated, handleLocalEcho); room.removeListener(RoomEvent.LocalEchoUpdated, handleLocalEcho);

View file

@ -212,7 +212,12 @@ function MessageNotifications() {
) { ) {
return; return;
} }
navigator.setAppBadge(unreadInfo.total); try {
navigator.setAppBadge(unreadInfo.total);
} catch (e) {
// Likely Firefox/Gecko-based and doesn't support badging API
}
if (showNotifications && notificationPermission('granted')) { if (showNotifications && notificationPermission('granted')) {
const avatarMxc = const avatarMxc =
room.getAvatarFallbackMember()?.getMxcAvatarUrl() ?? room.getMxcAvatarUrl(); room.getAvatarFallbackMember()?.getMxcAvatarUrl() ?? room.getMxcAvatarUrl();

View file

@ -127,7 +127,11 @@ const onPushNotification = async (event: PushEvent) => {
options.data = { ...options.data, ...pushData.data }; options.data = { ...options.data, ...pushData.data };
} }
if (typeof pushData.unread === 'number') { if (typeof pushData.unread === 'number') {
await self.navigator.setAppBadge(pushData.unread); try {
self.navigator.setAppBadge(pushData.unread);
} catch (e) {
// Likely Firefox/Gecko-based and doesn't support badging API
}
} else { } else {
await navigator.clearAppBadge(); await navigator.clearAppBadge();
} }