feat: 添加推送通知功能,支持Web Push订阅和发送

This commit is contained in:
2025-11-28 22:35:45 +08:00
parent a4bb8e984f
commit 35a948c515
13 changed files with 338 additions and 2 deletions
+22
View File
@@ -21,3 +21,25 @@ self.addEventListener("fetch", (event) => {
// If needed in future, add logic here, but keep it disabled for now.
return;
});
self.addEventListener('push', function(event) {
if (event.data) {
const payload = event.data.json();
const title = payload.title || 'New Notification';
const options = {
body: payload.body,
icon: payload.icon || '/favicon.png',
badge: payload.badge || '/favicon.png',
data: payload.url || '/'
};
event.waitUntil(self.registration.showNotification(title, options));
}
});
self.addEventListener('notificationclick', function(event) {
event.notification.close();
event.waitUntil(
clients.openWindow(event.notification.data)
);
});