Transforme le site en progressive web app

Ajoute un service worker (réseau d'abord, page hors ligne en secours),
les icônes PNG dont une maskable, un manifeste complet et les balises
iOS pour l'installation sur l'écran d'accueil.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Romulus21andClaude Opus 5.5 committed 2026-10-09 22:19:40 +02:00
1 parent 48e807ddce
commit 2346deab3c
8 files changed
+157 -1

No files matched your search

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

+9 -1
View File
@@ -1,11 +1,19 @@
{
"id": "/",
"name": "Lisette",
"short_name": "Lisette",
"description": "Mes listes de courses",
"lang": "fr",
"start_url": "/",
"scope": "/",
"display": "standalone",
"orientation": "portrait",
"background_color": "#bfe383",
"theme_color": "#bfe383",
"icons": [{ "src": "/favicon.svg", "sizes": "any", "type": "image/svg+xml" }]
"icons": [
{ "src": "/favicon.svg", "sizes": "any", "type": "image/svg+xml" },
{ "src": "/icons/icon-192.png", "sizes": "192x192", "type": "image/png" },
{ "src": "/icons/icon-512.png", "sizes": "512x512", "type": "image/png" },
{ "src": "/icons/maskable-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }
]
}
+45
View File
@@ -0,0 +1,45 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
<meta name="theme-color" content="#bfe383" />
<title>Lisette — hors ligne</title>
<link rel="icon" href="/favicon.svg" type="image/svg+xml" />
<style>
body {
margin: 0;
min-height: 100vh;
display: grid;
place-items: center;
background: #bfe383;
color: #1c1c24;
font-family: "Inter", ui-sans-serif, system-ui, sans-serif;
text-align: center;
padding: 1.5rem;
box-sizing: border-box;
}
img { width: 6rem; height: 6rem; }
h1 { font-size: 1.5rem; margin: 1rem 0 0.5rem; }
p { margin: 0 0 1.5rem; }
button {
font: inherit;
font-weight: 600;
padding: 0.75rem 1.5rem;
border: 2px solid #1c1c24;
border-radius: 0.875rem;
background: #fdfcf7;
box-shadow: 0 5px 0 0 #1c1c24;
cursor: pointer;
}
</style>
</head>
<body>
<main>
<img src="/favicon.svg" alt="" />
<h1>Pas de connexion</h1>
<p>Lisette a besoin du réseau pour afficher vos listes.</p>
<button onclick="location.reload()">Réessayer</button>
</main>
</body>
</html>
+96
View File
@@ -0,0 +1,96 @@
// Service worker de Lisette.
//
// Les pages et le wasm sont toujours demandés au réseau d'abord : les
// fichiers de /pkg ne sont pas versionnés, et servir un vieux wasm avec un
// HTML récent casserait l'hydratation. Le cache ne sert que de secours
// hors ligne. Les server functions (POST /api/…) ne passent pas par ici.
const VERSION = "v1";
const STATIC = `lisette-static-${VERSION}`;
const FONTS = "lisette-fonts";
const OFFLINE = "/offline.html";
const PRECACHE = [
OFFLINE,
"/favicon.svg",
"/manifest.webmanifest",
"/icons/icon-192.png",
"/icons/icon-512.png",
];
self.addEventListener("install", (event) => {
event.waitUntil(
caches
.open(STATIC)
.then((cache) => cache.addAll(PRECACHE))
.then(() => self.skipWaiting()),
);
});
self.addEventListener("activate", (event) => {
event.waitUntil(
caches
.keys()
.then((keys) =>
Promise.all(
keys
.filter((key) => key !== STATIC && key !== FONTS)
.map((key) => caches.delete(key)),
),
)
.then(() => self.clients.claim()),
);
});
self.addEventListener("fetch", (event) => {
const { request } = event;
if (request.method !== "GET") return;
const url = new URL(request.url);
// Pages : jamais mises en cache (contenu propre à l'utilisateur connecté).
if (request.mode === "navigate") {
event.respondWith(fetch(request).catch(() => caches.match(OFFLINE)));
return;
}
// Google Fonts : URLs versionnées, le cache d'abord.
if (
url.origin === "https://fonts.googleapis.com" ||
url.origin === "https://fonts.gstatic.com"
) {
event.respondWith(cacheFirst(FONTS, request));
return;
}
// Fichiers statiques du site : réseau d'abord, cache en secours.
if (url.origin === self.location.origin && !url.pathname.startsWith("/api/")) {
event.respondWith(networkFirst(STATIC, request));
}
});
async function cacheFirst(name, request) {
const cached = await caches.match(request);
if (cached) return cached;
const response = await fetch(request);
if (response.ok || response.type === "opaque") {
const cache = await caches.open(name);
cache.put(request, response.clone());
}
return response;
}
async function networkFirst(name, request) {
try {
const response = await fetch(request);
if (response.ok) {
const cache = await caches.open(name);
cache.put(request, response.clone());
}
return response;
} catch (err) {
const cached = await caches.match(request);
if (cached) return cached;
throw err;
}
}
+7
View File
@@ -32,6 +32,9 @@ pub fn shell(options: LeptosOptions) -> impl IntoView {
<AutoReload options=options.clone() />
<HydrationScripts options />
<MetaTags />
<script>
"if ('serviceWorker' in navigator) navigator.serviceWorker.register('/sw.js');"
</script>
</head>
<body class="bg-lime text-ink font-sans antialiased">
<App />
@@ -55,7 +58,11 @@ pub fn App() -> impl IntoView {
/>
<Link rel="manifest" href="/manifest.webmanifest" />
<Link rel="icon" href="/favicon.svg" type_="image/svg+xml" />
<Link rel="apple-touch-icon" href="/icons/apple-touch-icon.png" />
<Meta name="theme-color" content="#bfe383" />
<Meta name="mobile-web-app-capable" content="yes" />
<Meta name="apple-mobile-web-app-title" content="Lisette" />
<Meta name="apple-mobile-web-app-status-bar-style" content="default" />
<Title text="Lisette" />
<Router>