-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,44 @@ | ||
self.addEventListener("push", (event) => { | ||
if (!(self.Notification && self.Notification.permission === "granted")) { | ||
return; | ||
} | ||
if (!(self.Notification && self.Notification.permission === "granted")) { | ||
return; | ||
} | ||
|
||
const data = event.data?.json() ?? {}; | ||
const icon = "icon.png"; | ||
|
||
const data = event.data?.json() ?? {}; | ||
const icon = "icon.png"; | ||
const options = { | ||
lang: data.lang || "en-US", | ||
title: data.title, | ||
body: data.message, | ||
tag: data.tag, | ||
silent: data.silent, | ||
image: data.image, | ||
vibrate: [200, 100, 200], | ||
actions: data.actions || [], | ||
icon, | ||
data: { | ||
url: data.click_action | ||
} | ||
}; | ||
|
||
const options = { | ||
lang: data.lang || "en-US", | ||
title: data.title, | ||
body: data.message, | ||
tag: data.tag, | ||
image: data.image, | ||
vibrate: [200, 100, 200], | ||
actions: data.actions || [], | ||
icon, | ||
data: { | ||
url: data.click_action // Bu veriyi tıklandığında kullanıyoruz | ||
} | ||
}; | ||
//do your operations | ||
if (options.silent) | ||
return; | ||
event.waitUntil(self.registration.showNotification(data.title, options)); | ||
|
||
event.waitUntil(self.registration.showNotification(data.title, options)); | ||
}); | ||
|
||
self.addEventListener('notificationclick', function (event) { | ||
event.notification.close(); // Bildirimi kapat | ||
if (clients.openWindow && event.notification.data.url) { | ||
event.waitUntil(clients.openWindow(event.notification.data.url)); | ||
} | ||
event.notification.close(); // Bildirimi kapat | ||
if (clients.openWindow && event.notification.data.url) { | ||
event.waitUntil(clients.openWindow(event.notification.data.url)); | ||
} | ||
}); | ||
|
||
self.addEventListener('install', function (event) { | ||
self.skipWaiting(); // Hemen yüklenmesini sağla | ||
self.skipWaiting(); | ||
}); | ||
|
||
self.addEventListener('activate', function (event) { | ||
event.waitUntil(clients.claim()); // Hemen etkinleşmesini sağla | ||
event.waitUntil(clients.claim()); // Hemen etkinleşmesini sağla | ||
}); |