From 10734c622fb6d9ca19f8580242ff951ab9775045 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sun, 17 Nov 2019 15:01:58 +0300 Subject: handle initial page load better (reload to activate service worker) --- js/index.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'js/index.js') diff --git a/js/index.js b/js/index.js index 9c0f6a5..9aadc00 100644 --- a/js/index.js +++ b/js/index.js @@ -17,11 +17,24 @@ function cache_refresh(force) { navigator.serviceWorker.controller.postMessage("refresh-cache"); localforage.setItem("epube.cache-timestamp", ts); } else { - $(".dl-progress") - .show() - .addClass("alert-danger") - .html("Could not communicate with service worker. Try reloading the page."); + localforage.getItem("epube.initial-load-done").then(function(done) { + + console.log("initial load done", done); + + if (done) { + $(".dl-progress") + .show() + .addClass("alert-danger") + .html("Could not communicate with service worker. Try reloading the page."); + } else { + localforage.setItem("epube.initial-load-done", true).then(function() { + window.setTimeout(function() { + window.location.reload(); + }, 1000); + }); + } + }); } } -- cgit v1.2.3