check both navigator.permissions.query and Notification.permission for permissions ()

it seems these values are not kept in sync on iOS Safari, which may be the source
of badges not working on iOS PWA
This commit is contained in:
SatsAllDay 2023-11-25 12:32:41 -05:00 committed by GitHub
parent 80d49a7e57
commit a7b5534b7d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,14 +4,15 @@ export const clearNotifications = () => navigator.serviceWorker?.controller?.pos
const badgingApiSupported = (sw = window) => 'setAppBadge' in sw.navigator
const permissionGranted = async (sw = window, name = 'notifications') => {
const permissionGranted = async (sw = window) => {
const name = 'notifications'
let permission
try {
permission = await sw.navigator.permissions.query({ name })
} catch (err) {
console.error('Failed to check permissions', err)
}
return permission?.state === 'granted'
return permission?.state === 'granted' || sw.Notification?.permission === 'granted'
}
export const setAppBadge = async (sw = window, count) => {