From eed8a8409297ed62a5bee4703e3b4641fe617344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kasper=20Rynning-T=C3=B8nnesen?= Date: Fri, 14 Feb 2020 12:47:48 +0100 Subject: [PATCH] Forcing a refresh on new SW --- src/Vinlottis.vue | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Vinlottis.vue b/src/Vinlottis.vue index 970ee49..a629c0d 100644 --- a/src/Vinlottis.vue +++ b/src/Vinlottis.vue @@ -24,6 +24,19 @@ export default { "Arbeids arbeideren din er installert. Du kan nå gå offline frem til neste trekning." ); + serviceWorker.onupdatefound = () => { + const installingWorker = serviceWorker.installing; + installingWorker.onstatechange = () => { + if ( + installingWorker.state === "installed" && + navigator.serviceWorker.controller + ) { + // Preferably, display a message asking the user to reload... + location.reload(); + } + }; + }; + if (!("PushManager" in window)) { throw new Error("No Push API Support!"); }