From 4998be1a33965a7ad74ce90de255d6617af16f38 Mon Sep 17 00:00:00 2001 From: Jakob Stendahl Date: Tue, 9 Feb 2021 11:12:01 +0100 Subject: :wrench: Try another fix for service worker --- postbuild.sh | 2 +- src/js/main.js | 43 ++++++++++++++++++++++--------------------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/postbuild.sh b/postbuild.sh index 1c48fd8..5d5aa50 100755 --- a/postbuild.sh +++ b/postbuild.sh @@ -1,5 +1,5 @@ #!/bin/bash -PUBLISH_URL="" +PUBLISH_URL="/hoverbit-ble/" cd "dist" || exit 1 diff --git a/src/js/main.js b/src/js/main.js index 1c26af9..07d105c 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -4,29 +4,30 @@ import hoverControlModule from './hoverControlModule'; import { notif_alert, notif_warn, notif_info, notif_success } from './notification'; let sw = "service-worker.js"; -//if (navigator.serviceWorker) { -// navigator.serviceWorker.register(sw, {scope: '/hoverbit-ble/'}); -//} -navigator.serviceWorker.register( - sw, {scope: '/hoverbit-ble/'} -).then(registration => { - registration.onupdatefound = () => { - const installingWorker = registration.installing; - if (installingWorker == null) { return; } - installingWorker.onstatechange = () => { - if (installingWorker.state === "installed") { - if (navigator.serviceWorker.controller) { - notif_info("New content is available, relaunch the app to install it."); - } else { - notif_success("Content is cached for offline use."); +if (navigator.serviceWorker) { + // navigator.serviceWorker.register(sw, {scope: '/hoverbit-ble/'}); + //} + navigator.serviceWorker.register( + sw, {scope: '/hoverbit-ble/'} + ).then(registration => { + registration.onupdatefound = () => { + const installingWorker = registration.installing; + if (installingWorker == null) { return; } + installingWorker.onstatechange = () => { + if (installingWorker.state === "installed") { + if (navigator.serviceWorker.controller) { + notif_info("New content is available, relaunch the app to install it."); + } else { + notif_success("Content is cached for offline use."); + } } - } + }; }; - }; -}).catch(error => { - notif_alert("Could not install service worker..."); - console.error("Error during service worker registration:", error); -}); + }).catch(error => { + notif_alert("Could not install service worker..."); + console.error("Error during service worker registration:", error); + }); +} document.getElementById("btn_ignore_landscape_warning").addEventListener("click", () => { document.body.classList.add("ignore-landscape-warning"); -- cgit v1.2.3