auto update service worker and push new vue route when clicking message notification

This commit is contained in:
liamcottle
2025-02-13 20:37:29 +13:00
parent 88878af0ca
commit 0e5ee0e575
4 changed files with 45 additions and 5 deletions

View File

@@ -52,6 +52,22 @@ for(const route of routes){
}
}
// listen for postMessage events from service worker
navigator.serviceWorker.addEventListener("message", async (event) => {
if(event.data.type === "notificationclick"){
// get notification data
const notificationData = event.data.data;
// if notification data includes vue-route-push, push the route to vue
const vueRoutePush = notificationData["vue-route-push"];
if(vueRoutePush){
await router.push(vueRoutePush);
}
}
});
createApp(App)
.use(router)
.use(vClickOutside)