v0.6.3: immediate update on new version (skipping 24h service worker cooldown)

This commit is contained in:
kritzl 2024-06-10 13:55:39 +02:00
parent 12048f3a49
commit 2a0b6dbfe6
6 changed files with 35 additions and 16 deletions

View file

@ -232,6 +232,7 @@ async function loadOsmData() {
if (!internalData.stations[stationIndex].hasOwnProperty('coordinates')) {
const substitute = substituteData.filter(subs => subs.name === internalData.stations[stationIndex].name)
console.log(substitute)
if (substitute.length && substitute[0].hasOwnProperty('coordinates')) {
internalData.stations[stationIndex]['coordinates'] = substitute[0].coordinates;
}

View file

@ -53,7 +53,10 @@
y="0"
width="100"
height="100"
id="page4" /></sodipodi:namedview><defs
id="page4"
inkscape:export-filename="favicon-transparent.svg"
inkscape:export-xdpi="130.048"
inkscape:export-ydpi="130.048" /></sodipodi:namedview><defs
id="defs1" /><g
inkscape:label="Layer 1"
inkscape:groupmode="layer"

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

Before After
Before After

20
main.js
View file

@ -1,4 +1,4 @@
const version = '0.6.2'
const version = '0.6.3'
const minorVersion = version.split('.').splice(0, 2).join('.');
const numberFormat = new Intl.NumberFormat('de-DE', {
maximumFractionDigits: 1
@ -34,8 +34,18 @@ function closeDialog(selector) {
}
if ("serviceWorker" in navigator) {
console.log('installing sw');
navigator.serviceWorker.register("/sw.js").then((registration) => {
console.log('done installing sw');
});
navigator.serviceWorker.register("/sw.js")
.then((registration) => {
if (registration.installing) {
console.log('New Service Worker is installing...');
} else if (registration.waiting) {
console.log('Installed new service worker. Waiting for Update (up to 24h).');
} else if (registration.active) {
console.log('Service Worker is up to date.');
}
})
.catch((error) => {
// registration failed
console.error(`Registration failed with ${error}`);
});
}

View file

@ -404,7 +404,7 @@ body.has-dialog {
body {
font-family: system-ui, ui-sans-serif, sans-serif;
font-size: 1.2rem;
font-size: 1rem;
background-color: var(--bg);
color: var(--text);
}

View file

@ -171,7 +171,7 @@ body {
body {
font-family: system-ui, ui-sans-serif, sans-serif;
font-size: 1.2rem;
font-size: 1rem;
// colors
background-color: var(--bg);

21
sw.js
View file

@ -1,4 +1,4 @@
const version = '0.6.2'
const version = '0.6.3'
const consolePrefix = `[SW v${version}] `
const cacheName = `hvvstuhl-${version}`;
@ -36,13 +36,16 @@ const contentToCache = [
// Service worker Install: Cache all files
self.addEventListener("install", (e) => {
console.log("[Service Worker] Wird installiert....");
console.log(`${consolePrefix}Wird installiert....`);
e.waitUntil(
(async () => {
const cache = await caches.open(cacheName);
console.log("[Service Worker] Cache wird aufgebaut...");
console.log(`${consolePrefix} Cache wird aufgebaut...`);
await cache.addAll(contentToCache);
console.log("[Service Worker] FERTIG");
console.log(`${consolePrefix} > FERTIG`);
console.log(`${consolePrefix} Versuche Wartezeit zu überspringen...`);
await self.skipWaiting();
console.log(`${consolePrefix} > Erfolgreich`);
})(),
);
});
@ -60,8 +63,10 @@ const deleteOldCaches = async () => {
self.addEventListener("activate", (event) => {
event.waitUntil(
(async () => {
await deleteOldCaches()
await clients.claim();
await deleteOldCaches();
console.log(`${consolePrefix}Versuche Clients zu beanspruchen...`);
await self.clients.claim();
console.log(`${consolePrefix} > Erfolgreich`);
})(),
);
});
@ -79,12 +84,12 @@ self.addEventListener("fetch", (e) => {
const r = await caches.match(e.request);
if (r) {
console.log(`${consolePrefix} Im Cache gefunden.`);
console.log(`${consolePrefix} > Im Cache gefunden.`);
return r;
}
const response = await fetch(e.request);
const cache = await caches.open(cacheName);
console.log(`${consolePrefix} Nicht gefunden. Aktualisiere Cache: ${path}`);
console.log(`${consolePrefix} > Nicht gefunden. Aktualisiere Cache: ${path}`);
await cache.put(e.request, response.clone());
return response;
}else{