summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2020-05-07 09:50:27 +0300
committerAndrew Dolgov <[email protected]>2020-05-07 09:50:27 +0300
commit6c40c6da461294aad6d789154b6342734e0b502e (patch)
tree45305711facb212a2f0d55f5cc552f93f38ae39c /js
parenta2cf7386c0096deec0b62dab13117329711b4d99 (diff)
check file modification times for local syncing instead of relying on a sync interval
Diffstat (limited to 'js')
-rw-r--r--js/app.js14
1 files changed, 8 insertions, 6 deletions
diff --git a/js/app.js b/js/app.js
index 74c2fca..33333e8 100644
--- a/js/app.js
+++ b/js/app.js
@@ -37,6 +37,7 @@ const Cookie = {
const App = {
_dl_progress_timeout: false,
index_mode: "",
+ last_mtime: -1,
init: function() {
let refreshed_files = 0;
@@ -74,8 +75,7 @@ const App = {
}
if (event.data == 'client-reload') {
- const ts = parseInt(new Date().getTime()/1000);
- localforage.setItem("epube.cache-timestamp", ts);
+ localforage.setItem("epube.cache-timestamp", App.last_mtime);
window.location.reload()
}
@@ -156,9 +156,7 @@ const App = {
refreshCache: function(force) {
if ('serviceWorker' in navigator) {
localforage.getItem("epube.cache-timestamp").then(function(stamp) {
- const ts = parseInt(new Date().getTime()/1000);
-
- if (force || !stamp || ts - stamp > 3600 * 24 * 7) {
+ if (force || stamp != App.last_mtime) {
console.log('asking worker to refresh cache');
if (navigator.serviceWorker.controller) {
@@ -190,8 +188,12 @@ const App = {
});
}
}
-
});
+ } else {
+ $(".dl-progress")
+ .show()
+ .addClass("alert-danger")
+ .html("Could not communicate with service worker. Try reloading the page.");
}
},
initOfflineEvents: function() {