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 // Notification click event listener
self.addEventListener("notificationclick", (e) => { self.addEventListener("notificationclick", (e) => {
e.notification.close(); 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() { async function checkNewMessages() {
const cachedCredentials = await caches.open('cachedCredentials'); const cachedCredentials = await caches.open('cachedCredentials');
// Todo... // 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 // see browser compatibility: https://developer.mozilla.org/en-US/docs/Web/API/Web_Periodic_Background_Synchronization_API#browser_compatibility
self.addEventListener('periodicsync', (event) => { self.addEventListener('periodicsync', (event) => {
if (event.tag === 'check-new-messages') { if (event.tag === 'check-new-messages') {
self.registration.showNotification("Notification via periodicSync"); self.registration.showNotification(periodicSyncNewMsgReminderText);
event.waitUntil(checkNewMessages()); event.waitUntil(checkNewMessages());
} }

View file

@ -49,7 +49,7 @@ export default {
this.setDefaultLanguage(); this.setDefaultLanguage();
}, },
mounted() { mounted() {
registerServiceWorker(); registerServiceWorker(this.$t('notification.periodicSync_new_msg_reminder'));
/** /**
if ( if (
window.location.protocol == "http" && window.location.protocol == "http" &&

View file

@ -406,7 +406,8 @@
"enable": "Enable" "enable": "Enable"
}, },
"blocked_message": "Notification is blocked. Go to your device or browser settings to enable Notification", "blocked_message": "Notification is blocked. Go to your device or browser settings to enable Notification",
"not_supported": "Notification is not yet supported in Mobile" "not_supported": "Notification is not yet supported in Mobile",
"periodicSync_new_msg_reminder": "You may have new messages"
}, },
"emoji": { "emoji": {
"search": "Search...", "search": "Search...",

View file

@ -33,11 +33,12 @@ const registerPeriodicBackgroundSync = async (registration) => {
} }
} }
export function registerServiceWorker() { export function registerServiceWorker(periodicSyncNewMsgReminderTxt) {
if("serviceWorker" in navigator) { if("serviceWorker" in navigator) {
navigator.serviceWorker.register("./sw.js") navigator.serviceWorker.register("./sw.js")
.then(async registration => { .then(async registration => {
console.log('Service Worker registered with scope:', registration.scope); console.log('Service Worker registered with scope:', registration.scope);
registration.active.postMessage(periodicSyncNewMsgReminderTxt);
await registerPeriodicBackgroundSync(registration); await registerPeriodicBackgroundSync(registration);
}) })
.catch(error => { .catch(error => {