dont show push notifications in nonsupporting browsers
This commit is contained in:
parent
19c743f70d
commit
dc62751df4
@ -258,15 +258,21 @@ function NotificationAlert () {
|
|||||||
const [showAlert, setShowAlert] = useState(false)
|
const [showAlert, setShowAlert] = useState(false)
|
||||||
const [hasSubscription, setHasSubscription] = useState(false)
|
const [hasSubscription, setHasSubscription] = useState(false)
|
||||||
const [error, setError] = useState(null)
|
const [error, setError] = useState(null)
|
||||||
|
const [supported, setSupported] = useState(false)
|
||||||
const sw = useServiceWorker()
|
const sw = useServiceWorker()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const isSupported = sw.support.serviceWorker && sw.support.pushManager && sw.support.notification
|
const isSupported = sw.support.serviceWorker && sw.support.pushManager && sw.support.notification
|
||||||
const isDefaultPermission = sw.permission.notification === 'default'
|
if (isSupported) {
|
||||||
setShowAlert(isSupported && isDefaultPermission && !localStorage.getItem('hideNotifyPrompt'))
|
const isDefaultPermission = sw.permission.notification === 'default'
|
||||||
isSupported && sw.registration?.pushManager.getSubscription().then(subscription => setHasSubscription(!!subscription))
|
setShowAlert(isDefaultPermission && !localStorage.getItem('hideNotifyPrompt'))
|
||||||
|
sw.registration?.pushManager.getSubscription().then(subscription => setHasSubscription(!!subscription))
|
||||||
|
setSupported(true)
|
||||||
|
}
|
||||||
}, [sw])
|
}, [sw])
|
||||||
|
|
||||||
|
if (!supported) return null
|
||||||
|
|
||||||
const close = () => {
|
const close = () => {
|
||||||
localStorage.setItem('hideNotifyPrompt', 'yep')
|
localStorage.setItem('hideNotifyPrompt', 'yep')
|
||||||
setShowAlert(false)
|
setShowAlert(false)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user