Aded not-show notif when window visible
This commit is contained in:
parent
a7d7cb5627
commit
85edc95652
@ -1,3 +1,11 @@
|
|||||||
|
function isClientOpen(url) {
|
||||||
|
return self.clients.matchAll().then((clients) => {
|
||||||
|
return clients.some((client) => {
|
||||||
|
return client.url === url && "focus" in client;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
self.addEventListener("install", (event) => {
|
self.addEventListener("install", (event) => {
|
||||||
console.log("Service worker installing...");
|
console.log("Service worker installing...");
|
||||||
event.waitUntil(
|
event.waitUntil(
|
||||||
@ -20,6 +28,11 @@ self.addEventListener("push", (event) => {
|
|||||||
const data = event.data?.json() ?? {};
|
const data = event.data?.json() ?? {};
|
||||||
console.log("Received a push message", event, data);
|
console.log("Received a push message", event, data);
|
||||||
|
|
||||||
|
if(isClientOpen(data.url || data.link || `/web.html`)){
|
||||||
|
console.log("Client already open, not showing notification.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const title = data.title || "Something Has Happened";
|
const title = data.title || "Something Has Happened";
|
||||||
const message =
|
const message =
|
||||||
data.message || "Here's something you might want to check out.";
|
data.message || "Here's something you might want to check out.";
|
||||||
@ -41,6 +54,8 @@ self.addEventListener("push", (event) => {
|
|||||||
event.waitUntil(reg);
|
event.waitUntil(reg);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.addEventListener("notificationclick", (event) => {
|
self.addEventListener("notificationclick", (event) => {
|
||||||
console.log("Notification click Received.", event);
|
console.log("Notification click Received.", event);
|
||||||
event.notification.close();
|
event.notification.close();
|
||||||
|
Loading…
Reference in New Issue
Block a user