mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-08 00:00:28 +03:00
Prevent firefox from crashing because of no badging API
This commit is contained in:
parent
815a0ac7f4
commit
f24c6cce76
3 changed files with 16 additions and 3 deletions
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
|
|
|
||||||
|
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue