From 5fd015d56db69193baead6d7ae6a23f763d3dc58 Mon Sep 17 00:00:00 2001 From: sijanec Date: Tue, 9 Jun 2020 12:03:06 +0200 Subject: so users don't have to stay on a single page for 300 seconds for an update --- assets/js/app.js.bvr | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'assets') diff --git a/assets/js/app.js.bvr b/assets/js/app.js.bvr index 9bddb31..3d4cc6b 100644 --- a/assets/js/app.js.bvr +++ b/assets/js/app.js.bvr @@ -55,7 +55,7 @@ function gsecErrorHandlerUI(err) { var update_app_function = async function () { try { - $.get("/cache_name.txt?cache_kill="+Date.now(), (data, status) => { + $.get("/cache_name.txt?cache_kill=" + Date.now(), (data, status) => { var cache_name = data.split("///")[1].split("|||")[0]; var data_to_send = { action: "checkversion", @@ -103,16 +103,22 @@ var error_report_function = async function (msg, url, lineNo, columnNo, error) { window.onerror = error_report_function; window.onunhandledrejection = error_report_function; +async function try_app_update() { + localforage.getItem("lastUpdate").then((data) => { + if (Math.floor(Date.now() / 1000) > Number(data) + BEZIAPP_UPDATE_INTERVAL) { + // trigger an update + localforage.setItem("lastUpdate", Math.floor(Date.now() / 1000)).then(() => { + update_app_function(); + }); + } + }); +} document.addEventListener("DOMContentLoaded", () => { - var update_interval = setInterval(() => { // ok, it's value is never read, so what?! - localforage.getItem("lastUpdate").then((data) => { - if (Math.floor(Date.now() / 1000) > Number(data) + BEZIAPP_UPDATE_INTERVAL) { - // trigger an update - localforage.setItem("lastUpdate", Math.floor(Date.now() / 1000)) .then(()=>{ - update_app_function(); - }); - } - }); + try_app_update(); + var update_interval = setInterval(() => { + + try_app_update(); + }, 1000 * BEZIAPP_UPDATE_INTERVAL); }); \ No newline at end of file -- cgit v1.2.3