@@ -8,6 +8,8 @@ self.addEventListener('install', (event) => {
|
||||
// of event.waitUntil();
|
||||
})
|
||||
|
||||
const isIOS = /iPhone|iPad|iPod/i.test(navigator.userAgent)
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(
|
||||
clients.claim(), // Привязка нового сервис-воркера к текущим клиентам
|
||||
@@ -114,26 +116,52 @@ self.addEventListener('notificationclick', (event) => {
|
||||
type: 'notificationClick',
|
||||
tag: event.notification.tag,
|
||||
payload: event.notification.payload,
|
||||
url: urlToOpen,
|
||||
matchUrl: true,
|
||||
isIOS,
|
||||
}),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
if (isIOS && clientList.length > 0) {
|
||||
const client = clientList[0]
|
||||
return Promise.all([
|
||||
client.focus(),
|
||||
client.postMessage({
|
||||
type: 'notificationClick',
|
||||
tag: event.notification.tag,
|
||||
payload: event.notification.payload,
|
||||
url: urlToOpen,
|
||||
matchUrl: false,
|
||||
isIOS,
|
||||
}),
|
||||
])
|
||||
}
|
||||
|
||||
if (clients.openWindow) {
|
||||
console.log('open new window', urlToOpen)
|
||||
|
||||
return clients.openWindow(urlToOpen).then((client) => {
|
||||
if (!client) {
|
||||
if (client) {
|
||||
return client.postMessage({
|
||||
type: 'notificationClick',
|
||||
tag: event.notification.tag,
|
||||
payload: event.notification.payload,
|
||||
url: urlToOpen,
|
||||
matchUrl: true,
|
||||
isIOS,
|
||||
})
|
||||
} else {
|
||||
console.log('new window not opened')
|
||||
for (const client of clientList) {
|
||||
return client.postMessage({
|
||||
type: 'notificationClick',
|
||||
url: urlToOpen,
|
||||
tag: event.notification.tag,
|
||||
payload: event.notification.payload,
|
||||
url: urlToOpen,
|
||||
matchUrl: false,
|
||||
msg: 'new window not opened',
|
||||
isIOS,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -144,11 +172,11 @@ self.addEventListener('notificationclick', (event) => {
|
||||
for (const client of clientList) {
|
||||
return client.postMessage({
|
||||
type: 'notificationClick',
|
||||
url: urlToOpen,
|
||||
tag: event.notification.tag,
|
||||
payload: event.notification.payload,
|
||||
url: urlToOpen,
|
||||
matchUrl: false,
|
||||
msg: 'clients.openWindow not available',
|
||||
isIOS,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user