Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
anilsnl committed Aug 20, 2023
1 parent d6dc7fc commit 22d8a12
Showing 1 changed file with 30 additions and 25 deletions.
55 changes: 30 additions & 25 deletions samples/AdsPushSample.VapidClient/service-worker.js
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
});

0 comments on commit 22d8a12

Please sign in to comment.