dont show push notifications in nonsupporting browsers

This commit is contained in:
keyan 2023-07-04 18:44:03 -05:00
parent 19c743f70d
commit dc62751df4
1 changed files with 9 additions and 3 deletions

View File

@ -258,15 +258,21 @@ function NotificationAlert () {
const [showAlert, setShowAlert] = useState(false)
const [hasSubscription, setHasSubscription] = useState(false)
const [error, setError] = useState(null)
const [supported, setSupported] = useState(false)
const sw = useServiceWorker()
useEffect(() => {
const isSupported = sw.support.serviceWorker && sw.support.pushManager && sw.support.notification
const isDefaultPermission = sw.permission.notification === 'default'
setShowAlert(isSupported && isDefaultPermission && !localStorage.getItem('hideNotifyPrompt'))
isSupported && sw.registration?.pushManager.getSubscription().then(subscription => setHasSubscription(!!subscription))
if (isSupported) {
const isDefaultPermission = sw.permission.notification === 'default'
setShowAlert(isDefaultPermission && !localStorage.getItem('hideNotifyPrompt'))
sw.registration?.pushManager.getSubscription().then(subscription => setHasSubscription(!!subscription))
setSupported(true)
}
}, [sw])
if (!supported) return null
const close = () => {
localStorage.setItem('hideNotifyPrompt', 'yep')
setShowAlert(false)