25 lines
717 B
JavaScript
25 lines
717 B
JavaScript
// Service Worker for Push Notifications
|
|
self.addEventListener('push', (event) => {
|
|
const data = event.data ? event.data.json() : { title: 'New Episode!', body: 'Check out the latest podcast episode.' };
|
|
|
|
const options = {
|
|
body: data.body,
|
|
icon: '/assets/uploads/images/icon.png', // Fallback icon
|
|
badge: '/assets/uploads/images/badge.png',
|
|
data: {
|
|
url: data.url || '/'
|
|
}
|
|
};
|
|
|
|
event.waitUntil(
|
|
self.registration.showNotification(data.title, options)
|
|
);
|
|
});
|
|
|
|
self.addEventListener('notificationclick', (event) => {
|
|
event.notification.close();
|
|
event.waitUntil(
|
|
clients.openWindow(event.notification.data.url)
|
|
);
|
|
});
|