Merge branch '419-notification-via-periodicSync-general-new-message-reminder-text' into 'dev'
periodicSync's Notification title update See merge request keanuapp/keanuapp-weblite!295
This commit is contained in:
commit
7bc6a6eee0
4 changed files with 13 additions and 4 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
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 +21,10 @@ self.addEventListener("notificationclick", (e) => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
self.addEventListener("message", (event) => {
|
||||||
|
periodicSyncNewMsgReminderText = event.data;
|
||||||
|
});
|
||||||
|
|
||||||
async function checkNewMessages() {
|
async function checkNewMessages() {
|
||||||
const cachedCredentials = await caches.open('cachedCredentials');
|
const cachedCredentials = await caches.open('cachedCredentials');
|
||||||
// Todo...
|
// Todo...
|
||||||
|
|
@ -28,7 +34,8 @@ 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");
|
let notificationTitle = periodicSyncNewMsgReminderText || "You may have new messages";
|
||||||
|
self.registration.showNotification(notificationTitle);
|
||||||
|
|
||||||
event.waitUntil(checkNewMessages());
|
event.waitUntil(checkNewMessages());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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" &&
|
||||||
|
|
|
||||||
|
|
@ -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...",
|
||||||
|
|
|
||||||
|
|
@ -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 => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue