From 8d4d2d624063fc9b4a0d53a66b23c55f8553b161 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Thu, 9 Feb 2023 11:28:15 -0800 Subject: [PATCH] app: fix sw registration --- src/App.vue | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/App.vue b/src/App.vue index 9a752b77..8ba24320 100644 --- a/src/App.vue +++ b/src/App.vue @@ -206,6 +206,25 @@ export default defineComponent({ } }, + async beforeMount() { + if ("serviceWorker" in navigator) { + // Use the window load event to keep the page load performant + window.addEventListener("load", async () => { + try { + const url = generateUrl("/apps/memories/service-worker.js"); + const registration = await navigator.serviceWorker.register(url, { + scope: generateUrl("/apps/memories"), + }); + console.log("SW registered: ", registration); + } catch (error) { + console.error("SW registration failed: ", error); + } + }); + } else { + console.debug("Service Worker is not enabled on this browser."); + } + }, + methods: { navItemsAll() { return [ @@ -277,25 +296,6 @@ export default defineComponent({ ]; }, - async beforeMount() { - if ("serviceWorker" in navigator) { - // Use the window load event to keep the page load performant - window.addEventListener("load", async () => { - try { - const url = generateUrl("/apps/memories/service-worker.js"); - const registration = await navigator.serviceWorker.register(url, { - scope: generateUrl("/apps/memories"), - }); - console.log("SW registered: ", registration); - } catch (error) { - console.error("SW registration failed: ", error); - } - }); - } else { - console.debug("Service Worker is not enabled on this browser."); - } - }, - linkClick() { const nav: any = this.$refs.nav; if (globalThis.windowInnerWidth <= 1024) nav?.toggleNavigation(false);