periodicSync Notification text message update

This commit is contained in:
10G Meow 2024-05-26 16:56:36 +03:00
parent 7601ca68ce
commit 638e9bf505
4 changed files with 11 additions and 4 deletions

View file

@ -1,3 +1,4 @@
var periodicSyncNewMsgReminderText;
// Notification click event listener
self.addEventListener("notificationclick", (e) => {
e.notification.close();
@ -19,6 +20,10 @@ self.addEventListener("notificationclick", (e) => {
);
});
self.addEventListener("message", (event) => {
periodicSyncNewMsgReminderText = event.data || "You may have new messages"
});
async function checkNewMessages() {
const cachedCredentials = await caches.open('cachedCredentials');
// Todo...
@ -28,7 +33,7 @@ async function checkNewMessages() {
// see browser compatibility: https://developer.mozilla.org/en-US/docs/Web/API/Web_Periodic_Background_Synchronization_API#browser_compatibility
self.addEventListener('periodicsync', (event) => {
if (event.tag === 'check-new-messages') {
self.registration.showNotification("Notification via periodicSync");
self.registration.showNotification(periodicSyncNewMsgReminderText);
event.waitUntil(checkNewMessages());
}