From 0d4d63927cb2b608c65641859bfe43ba6b17b204 Mon Sep 17 00:00:00 2001 From: sijanec Date: Mon, 8 Jun 2020 23:04:24 +0200 Subject: uhhh, didn't even test ): --- assets/root/sw.js.bvr | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'assets/root') diff --git a/assets/root/sw.js.bvr b/assets/root/sw.js.bvr index 1a823d4..45ac9dd 100644 --- a/assets/root/sw.js.bvr +++ b/assets/root/sw.js.bvr @@ -118,6 +118,30 @@ self.addEventListener("activate", evt => { ); }); +async function sw_asynclycheckversion (data) { + try { + var names = await caches.keys(); + console.log("[sw.js] checkversion: ***** checkversion v0 for BežiApp ***** hello, world!"); + if(!(data.valid_cache_name == undefined || data.valid_cache_name == null || data.valid_cache_name == "")) { + var valid_cache_name = data.valid_cache_name; + console.log("[sw.js] checkversion: requested version (cachename) " + valid_cache_name); + } else { + var valid_cache_name = static_cache_name; + console.log("[sw.js] checkversion: no version to keep specified, using current "+valid_cache_name+", but that makes no sense to me."); + } + console.log("[sw.js] checkversion: deleting caches that don't match that cache name ..."); + for (let name of names) { + if(valid_cache_name != name) { + caches.delete(name); + console.log("[sw.js] checkversion: done requesting delete of cache " + name); + } + } + console.log("[sw.js] checkversion: done, exiting!"); + } catch (e) { + console.log("[sw.js] checkversion: !!! ERRORS! (caught)"); + } +} + self.addEventListener("message", event => { if (event.data) { @@ -141,27 +165,7 @@ self.addEventListener("message", event => { } }); } else if (data.action.startsWith("checkversion")) { - try { - var names = await caches.keys(); - console.log("[sw.js] checkversion: ***** checkversion v0 for BežiApp ***** hello, world!"); - if(!(data.valid_cache_name == undefined || data.valid_cache_name == null || data.valid_cache_name == "")) { - var valid_cache_name = data.valid_cache_name; - console.log("[sw.js] checkversion: requested version (cachename) " + valid_cache_name); - } else { - var valid_cache_name = static_cache_name; - console.log("[sw.js] checkversion: no version to keep specified, using current "+valid_cache_name+", but that makes no sense to me."); - } - console.log("[sw.js] checkversion: deleting caches that don't match that cache name ..."); - for (let name of names) { - if(valid_cache_name != name) { - caches.delete(name); - console.log("[sw.js] checkversion: done requesting delete of cache " + name); - } - } - console.log("[sw.js] checkversion: done, exiting!"); - } catch (e) { - console.log("[sw.js] checkversion: !!! ERRORS! (caught)"); - } + sw_asynclycheckversion(data); } } }); -- cgit v1.2.3