@@ -34,28 +34,41 @@ self.addEventListener('push', (event) => {
|
||||
})
|
||||
|
||||
self.addEventListener('notificationclick', (event) => {
|
||||
console.log('клик на уведомление', event.notification)
|
||||
event.notification.close()
|
||||
|
||||
// Открытие URL из данных уведомления
|
||||
event.waitUntil(
|
||||
clients.matchAll({ type: 'window' }).then((clientList) => {
|
||||
for (const client of clientList) {
|
||||
if (client.url === event.notification.data.url && 'focus' in client) {
|
||||
console.log('клик на уведомление', event.notification.tag)
|
||||
clients
|
||||
.matchAll({ type: 'window', includeUncontrolled: true })
|
||||
.then((clientList) => {
|
||||
for (const client of clientList) {
|
||||
console.log('client.url', client.url)
|
||||
if (client.url === event.notification.data.url && 'focus' in client) {
|
||||
console.log('фокус')
|
||||
|
||||
return Promise.all([
|
||||
client.focus(),
|
||||
client.postMessage({
|
||||
type: 'notificationClick',
|
||||
tag: event.notification.tag,
|
||||
payload: event.notification.payload,
|
||||
}),
|
||||
])
|
||||
return Promise.all([
|
||||
client.focus(),
|
||||
client.postMessage({
|
||||
type: 'notificationClick',
|
||||
tag: event.notification.tag,
|
||||
payload: event.notification.payload,
|
||||
}),
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
if (clients.openWindow) {
|
||||
return clients.openWindow(event.notification.data.url)
|
||||
}
|
||||
}),
|
||||
if (clients.openWindow) {
|
||||
console.log('новое окно')
|
||||
return clients.openWindow(event.notification.data.url).then((client) => {
|
||||
if (client) {
|
||||
return client.focus()
|
||||
}
|
||||
console.log('новое окно не открылось')
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
}),
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user