mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-06-06 10:07:36 +08:00
feat: improve push notifications
This commit is contained in:
@@ -1,9 +1,23 @@
|
||||
self.addEventListener('push', function(event) {
|
||||
const data = event.data ? event.data.text() : 'New notification';
|
||||
let payload = { body: 'New notification', url: '/' }
|
||||
try {
|
||||
if (event.data) payload = JSON.parse(event.data.text())
|
||||
} catch (e) {
|
||||
if (event.data) payload.body = event.data.text()
|
||||
}
|
||||
event.waitUntil(
|
||||
self.registration.showNotification('OpenIsle', {
|
||||
body: data,
|
||||
icon: '/favicon.ico'
|
||||
body: payload.body,
|
||||
icon: '/favicon.ico',
|
||||
data: { url: payload.url }
|
||||
})
|
||||
);
|
||||
});
|
||||
)
|
||||
})
|
||||
|
||||
self.addEventListener('notificationclick', function(event) {
|
||||
const url = event.notification.data && event.notification.data.url
|
||||
event.notification.close()
|
||||
if (url) {
|
||||
event.waitUntil(clients.openWindow(url))
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user