check both `navigator.permissions.query` and `Notification.permission` for permissions (#655)
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:
parent
80d49a7e57
commit
a7b5534b7d
|
@ -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) => {
|
||||
|
|
Loading…
Reference in New Issue