test SHIT
This commit is contained in:
parent
a2daac6dd2
commit
e0eaf961c4
1 changed files with 15 additions and 1 deletions
16
src/sw.js
16
src/sw.js
|
@ -59,7 +59,21 @@ const setSettings = async () => {
|
|||
}
|
||||
|
||||
const showPushNotification = async (event) => {
|
||||
return self.registration.showNotification(res.title, res)
|
||||
const activeClients = await getWindowClients()
|
||||
await setSettings()
|
||||
// Only show push notifications if all tabs/windows are closed
|
||||
if (activeClients.length === 0) {
|
||||
const data = event.data.json()
|
||||
|
||||
const url = `${self.registration.scope}api/v1/notifications/${data.notification_id}`
|
||||
const notification = await fetch(url, { headers: { Authorization: 'Bearer ' + data.access_token } })
|
||||
const notificationJson = await notification.json()
|
||||
const parsedNotification = parseNotification(notificationJson)
|
||||
|
||||
const res = prepareNotificationObject(parsedNotification, i18n)
|
||||
|
||||
return self.registration.showNotification(res.title, res)
|
||||
}
|
||||
}
|
||||
|
||||
self.addEventListener('push', async (event) => {
|
||||
|
|
Loading…
Add table
Reference in a new issue