diff --git a/public/icons/apple-touch-icon.png b/public/icons/apple-touch-icon.png
new file mode 100644
index 0000000..8e49ec1
Binary files /dev/null and b/public/icons/apple-touch-icon.png differ
diff --git a/public/icons/icon-192.png b/public/icons/icon-192.png
new file mode 100644
index 0000000..c24afd7
Binary files /dev/null and b/public/icons/icon-192.png differ
diff --git a/public/icons/icon-512.png b/public/icons/icon-512.png
new file mode 100644
index 0000000..993ef41
Binary files /dev/null and b/public/icons/icon-512.png differ
diff --git a/public/icons/maskable-512.png b/public/icons/maskable-512.png
new file mode 100644
index 0000000..bda9071
Binary files /dev/null and b/public/icons/maskable-512.png differ
diff --git a/public/manifest.webmanifest b/public/manifest.webmanifest
index d0876e0..3ba5fc3 100644
--- a/public/manifest.webmanifest
+++ b/public/manifest.webmanifest
@@ -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" }
+ ]
}
diff --git a/public/offline.html b/public/offline.html
new file mode 100644
index 0000000..e859f91
--- /dev/null
+++ b/public/offline.html
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+ Lisette — hors ligne
+
+
+
+
+
+
+ Pas de connexion
+ Lisette a besoin du réseau pour afficher vos listes.
+
+
+
+
diff --git a/public/sw.js b/public/sw.js
new file mode 100644
index 0000000..05fab72
--- /dev/null
+++ b/public/sw.js
@@ -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;
+ }
+}
diff --git a/src/app/mod.rs b/src/app/mod.rs
index ed1e25b..3695d6d 100644
--- a/src/app/mod.rs
+++ b/src/app/mod.rs
@@ -32,6 +32,9 @@ pub fn shell(options: LeptosOptions) -> impl IntoView {
+
@@ -55,7 +58,11 @@ pub fn App() -> impl IntoView {
/>
+
+
+
+