Compare commits
No commits in common. "6f643f70701d0297c2331b22286e01b442fe7089" and "c3dbf63419098cd27cef37826411ae0dee35a8f4" have entirely different histories.
6f643f7070
...
c3dbf63419
62
index.js
62
index.js
@ -4,45 +4,35 @@ import BaseView from "/ui/base_view.js";
|
|||||||
import InfoView from "/ui/info_view.js";
|
import InfoView from "/ui/info_view.js";
|
||||||
import Layout from "/ui/layout.js";
|
import Layout from "/ui/layout.js";
|
||||||
|
|
||||||
try {
|
navigator.storage.persisted().then((persistent) => {
|
||||||
navigator.serviceWorker.register("/service-worker.js", { scope: "/" });
|
if (!persistent && navigator.vendor === "Apple Computer, Inc.") {
|
||||||
} catch (error) {
|
const question =
|
||||||
console.error("failed to register service worker: ", error);
|
"S'schaut so aus als würdest du an Safari-Browser benutzn. S'isch " +
|
||||||
}
|
"leida aba so, dass dea manchmoi selbstständig oanfach Datn löscht, " +
|
||||||
|
"wenn ma a Seitn z'lang nit heanimmt. Des is füa an Watterblock " +
|
||||||
|
"natürlich eha schlecht.\n" +
|
||||||
|
"\n" +
|
||||||
|
"Wennst magst kannt ma aba probian ob ma des Löschn fian Block " +
|
||||||
|
"ausschaltn kenna. Wennst magst klick oanfach auf \"Ok\"!\n" +
|
||||||
|
"\n" +
|
||||||
|
"Wenns gangen is kimsch danach glei zum Block, und falls nit bekommst " +
|
||||||
|
"dazu no a extra Nachricht.";
|
||||||
|
|
||||||
try {
|
const failure =
|
||||||
navigator.storage.persisted().then((persistent) => {
|
"S'isch leida nit gangen, Safari hat na gsagt. Du kansch entweda an " +
|
||||||
if (!persistent && navigator.vendor === "Apple Computer, Inc.") {
|
"andern Browser heanemmen, oder halt damit Leben wenn Safari deine " +
|
||||||
const question =
|
"Datn löscht.\n" +
|
||||||
"S'schaut so aus als würdest du an Safari-Browser benutzn. S'isch " +
|
"\n" +
|
||||||
"leida aba so, dass dea manchmoi selbstständig oanfach Datn löscht, " +
|
"#JustSafariThings";
|
||||||
"wenn ma a Seitn z'lang nit heanimmt. Des is füa an Watterblock " +
|
|
||||||
"natürlich eha schlecht.\n" +
|
|
||||||
"\n" +
|
|
||||||
"Wennst magst kannt ma aba probian ob ma des Löschn fian Block " +
|
|
||||||
"ausschaltn kenna. Wennst magst klick oanfach auf \"Ok\"!\n" +
|
|
||||||
"\n" +
|
|
||||||
"Wenns gangen is kimsch danach glei zum Block, und falls nit " +
|
|
||||||
"bekommst dazu no a extra Nachricht.";
|
|
||||||
|
|
||||||
const failure =
|
if (window.confirm(question)) {
|
||||||
"S'isch leida nit gangen, Safari hat na gsagt. Du kansch entweda an " +
|
navigator.storage.persist().then((persistent) => {
|
||||||
"andern Browser heanemmen, oder halt damit Leben wenn Safari deine " +
|
if (!persistent)
|
||||||
"Datn löscht.\n" +
|
window.alert(failure);
|
||||||
"\n" +
|
});
|
||||||
"#JustSafariThings";
|
|
||||||
|
|
||||||
if (window.confirm(question)) {
|
|
||||||
navigator.storage.persist().then((persistent) => {
|
|
||||||
if (!persistent)
|
|
||||||
window.alert(failure);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
} catch (error) {
|
});
|
||||||
console.error("failed to try to persist in safary: ", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
m.route.prefix = "";
|
m.route.prefix = "";
|
||||||
m.route(document.body, "/", {
|
m.route(document.body, "/", {
|
||||||
|
|||||||
@ -1,101 +0,0 @@
|
|||||||
const CACHE_NAME = "v1";
|
|
||||||
|
|
||||||
async function cacheResources() {
|
|
||||||
const cache = await caches.open(CACHE_NAME);
|
|
||||||
await cache.addAll([
|
|
||||||
"/",
|
|
||||||
"/style.css",
|
|
||||||
"/vendored/qunit-2.25.0.js",
|
|
||||||
"/vendored/material-icons.css",
|
|
||||||
"/vendored/normalize-8.0.1.css",
|
|
||||||
"/vendored/qunit-2.25.0.css",
|
|
||||||
"/vendored/mithril-2.3.8.js",
|
|
||||||
"/vendored/material-icons.ttf",
|
|
||||||
"/index.js",
|
|
||||||
"/models/round.js",
|
|
||||||
"/models/round_result.js",
|
|
||||||
"/models/game_rules.js",
|
|
||||||
"/models/game.js",
|
|
||||||
"/models/session.js",
|
|
||||||
"/data/db.js",
|
|
||||||
"/data/session_repo.js",
|
|
||||||
"/ui/info_view.js",
|
|
||||||
"/ui/round.js",
|
|
||||||
"/ui/session_list.js",
|
|
||||||
"/ui/field.css",
|
|
||||||
"/ui/game.js",
|
|
||||||
"/ui/session-list.css",
|
|
||||||
"/ui/round.css",
|
|
||||||
"/ui/session.js",
|
|
||||||
"/ui/box.css",
|
|
||||||
"/ui/layout.js",
|
|
||||||
"/ui/session_head.js",
|
|
||||||
"/ui/base_view.js",
|
|
||||||
"/ui/button.css",
|
|
||||||
"/ui/session-view.css",
|
|
||||||
"/ui/layout.css",
|
|
||||||
"/ui/splash.css",
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isStale(response) {
|
|
||||||
let date = response.headers.get("Date");
|
|
||||||
if (date === null)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
date = new Date(date);
|
|
||||||
date.setTime(date.getTime() + 60 * 60 * 1000);
|
|
||||||
return date <= new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function revalidateIndex() {
|
|
||||||
const index = await caches.match("/");
|
|
||||||
if (!index || isStale(index))
|
|
||||||
await cacheResources();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getFromCache(request, event) {
|
|
||||||
const response = await caches.match(request);
|
|
||||||
if (!response)
|
|
||||||
return null;
|
|
||||||
if (isStale(response))
|
|
||||||
event.waitUntil(getFromNetwork(request, event));
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function putInCache(request, response) {
|
|
||||||
const cache = await cache.open(CACHE_NAME);
|
|
||||||
await cache.put(request, response);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getFromNetwork(request, event) {
|
|
||||||
const response = await fetch(request);
|
|
||||||
event.waitUntil(putInCache(request, response.clone()));
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getResponse(request, event) {
|
|
||||||
const cached = await getFromCache(request, event);
|
|
||||||
if (cached)
|
|
||||||
return cached;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const fetched = await getFromNetwork(request, event);
|
|
||||||
return fetched;
|
|
||||||
} catch {
|
|
||||||
const index = await getFromCache("/");
|
|
||||||
if (index)
|
|
||||||
return index;
|
|
||||||
|
|
||||||
return new Response("Irgendwas is komplett faul", { status: 500 });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.addEventListener("install", (event) => {
|
|
||||||
event.waitUntil(cacheResources());
|
|
||||||
});
|
|
||||||
|
|
||||||
self.addEventListener("fetch", (event) => {
|
|
||||||
event.waitUntil(revalidateIndex());
|
|
||||||
event.respondWith(getResponse(event.request, event));
|
|
||||||
})
|
|
||||||
Loading…
Reference in New Issue
Block a user