feat: add PWA support

This commit is contained in:
2026-07-31 22:52:18 +02:00
parent 6998e8bdb7
commit 530162cbf7
11 changed files with 156 additions and 0 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

+8
View File
@@ -0,0 +1,8 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" role="img" aria-label="Pi Car Companion">
<rect width="512" height="512" fill="#10130f"/>
<circle cx="256" cy="256" r="164" fill="#171b16" stroke="#30372d" stroke-width="16"/>
<path d="M148 300a120 120 0 1 1 216 0" fill="none" stroke="#b9e769" stroke-width="30" stroke-linecap="round"/>
<path d="m256 268 73-82" fill="none" stroke="#f0f2eb" stroke-width="26" stroke-linecap="round"/>
<circle cx="256" cy="268" r="30" fill="#b9e769"/>
<path d="M173 337h166" fill="none" stroke="#f0f2eb" stroke-width="24" stroke-linecap="round"/>
</svg>

After

Width:  |  Height:  |  Size: 610 B

+33
View File
@@ -0,0 +1,33 @@
{
"id": "/",
"name": "Pi Car Companion",
"short_name": "Pi Car",
"description": "Local dashboard for your Raspberry Pi car companion.",
"start_url": "/",
"scope": "/",
"display": "standalone",
"orientation": "landscape",
"background_color": "#10130f",
"theme_color": "#10130f",
"categories": ["navigation", "utilities"],
"icons": [
{
"src": "/pwa-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any"
},
{
"src": "/pwa-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any"
},
{
"src": "/pwa-maskable-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
}
]
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

+63
View File
@@ -0,0 +1,63 @@
const CACHE_NAME = "pi-car-companion-v1";
const APP_SHELL = [
"/",
"/manifest.webmanifest",
"/icon.svg",
"/pwa-192x192.png",
"/pwa-512x512.png",
"/pwa-maskable-512x512.png",
"/apple-touch-icon.png"
];
self.addEventListener("install", (event) => {
event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL)));
self.skipWaiting();
});
self.addEventListener("activate", (event) => {
event.waitUntil(
caches
.keys()
.then((keys) => Promise.all(keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key))))
.then(() => self.clients.claim())
);
});
self.addEventListener("fetch", (event) => {
const request = event.request;
if (request.method !== "GET") return;
const url = new URL(request.url);
if (url.origin !== self.location.origin || url.pathname.startsWith("/api/") || url.pathname === "/healthz") return;
if (request.mode === "navigate") {
event.respondWith(
fetch(request)
.then((response) => {
if (response.ok) {
const copy = response.clone();
event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.put("/", copy)));
}
return response;
})
.catch(() => caches.match("/"))
);
return;
}
if (url.pathname.startsWith("/assets/") || APP_SHELL.includes(url.pathname)) {
event.respondWith(
caches.match(request).then(
(cached) =>
cached ??
fetch(request).then((response) => {
if (response.ok) {
const copy = response.clone();
event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.put(request, copy)));
}
return response;
})
)
);
}
});