mirror of
https://github.com/GuerillaStudio/souvenir.git
synced 2025-01-20 22:30:20 +00:00
add notification
This commit is contained in:
parent
d7032c8aac
commit
7126c5df91
4 changed files with 24 additions and 18 deletions
|
@ -1,7 +1,7 @@
|
|||
import store from '~/src/store'
|
||||
|
||||
export default () => {
|
||||
if ('serviceWorker' in navigator && process.env.NODE_ENV === 'production') {
|
||||
if ('serviceWorker' in navigator) {
|
||||
navigator.serviceWorker
|
||||
.register(new URL('~/src/service-worker.js', import.meta.url), { type: 'module' })
|
||||
.then(registration => {
|
||||
|
|
|
@ -16,3 +16,17 @@ async function activate () {
|
|||
}
|
||||
|
||||
addEventListener('activate', e => e.waitUntil(activate()))
|
||||
|
||||
addEventListener('notificationclick', event => {
|
||||
event.notification.close()
|
||||
|
||||
event.waitUntil(
|
||||
clients
|
||||
.matchAll({ type: 'window' })
|
||||
.then(clientList => {
|
||||
for (const client of clientList) {
|
||||
return client.focus()
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
|
|
|
@ -96,16 +96,12 @@ export default {
|
|||
this.downloadReady = true
|
||||
|
||||
if (document.hidden && ('Notification' in window) && Notification.permission === 'granted') {
|
||||
const notification = new Notification('You can now download your souvenir', {
|
||||
navigator.serviceWorker.ready.then((registration) => {
|
||||
registration.showNotification('You can now download your souvenir', {
|
||||
body: 'Thank you for your patience.',
|
||||
icon: appLogo
|
||||
})
|
||||
|
||||
notification.addEventListener('click', () => {
|
||||
parent.focus()
|
||||
}, {
|
||||
once: true
|
||||
})
|
||||
}).catch(console.error)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -85,12 +85,8 @@ export default {
|
|||
}
|
||||
|
||||
function showNotificationButton () {
|
||||
return false
|
||||
|
||||
// TODO: fuuuuuuuuuuuuu android, I don't want to spawn notifications from a fucking service worker :<
|
||||
|
||||
// return ('Notification' in window) &&
|
||||
// Notification.permission !== 'granted' &&
|
||||
// Notification.permission !== 'denied'
|
||||
return ('Notification' in window) &&
|
||||
Notification.permission !== 'granted' &&
|
||||
Notification.permission !== 'denied'
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Reference in a new issue