PWA: Manifest, Service Worker, Icons und Offline-Seite

This commit is contained in:
OpenCode 2026-11-13 00:46:02 +01:00
parent ec88c8ebac
commit 67a1614081
19 changed files with 472 additions and 5 deletions

View file

@ -34,6 +34,23 @@ Die Anforderungen stammen aus
- **Übersicht** mit heutiger Auslastung, freien Anhängern, nächsten Übergaben
und Rücknahmen sowie offenen Erinnerungen.
## PWA / Installation
Die App ist als Progressive Web App eingerichtet:
- `manifest.webmanifest` mit Namen, Farben, Icons (192/512, maskable) und
Shortcuts für Kalender, neue Buchung und Erinnerungen.
- `sw.js` macht die App installierbar, lädt statische Assets schneller und
zeigt offline eine eigene Seite. **Buchungen und HTML-Seiten werden nicht
gecacht**, damit niemand veraltete Daten sieht – die Terminplanung braucht
online immer den aktuellen Stand.
- Installation: in Chrome/Edge über das Installations-Symbol in der Adresszeile
oder **Menü → App installieren**; auf iPhone/iPad über **Teilen → Zum
Home-Bildschirm**. Ein Installations-Eintrag erscheint zusätzlich im
Benutzermenü, sobald der Browser die Installation anbietet.
- Voraussetzung ist HTTPS (live erfüllt). Lokal funktioniert der Service Worker
auch über `http://127.0.0.1`.
## Technik
- PHP 8.1+ (getestet mit 8.3), MariaDB 10.11, keine Build-Tools nötig.

View file

@ -89,7 +89,7 @@ function url(string $path = '/'): string
}
/** Cache-Buster: bei Änderungen an app.css/app.js erhöhen. */
const DIC_ASSET_VERSION = '1';
const DIC_ASSET_VERSION = '2';
function asset(string $path): string
{

View file

@ -127,6 +127,23 @@ sind die primäre Anzeige und funktionieren ohne Mailversand.
| 9. Übersicht | Dashboard mit Auslastung, freien Anhängern, Übergaben/Rücknahmen, Erinnerungen |
| Benutzerverwaltung tippspiel2027 | Admin-only, Vorname/Nachname/Passwort, keine Selbstregistrierung |
## PWA
- **Manifest:** `web/manifest.webmanifest` (Name, Theme `#196abc`, Icons in
`web/assets/icons/`, Shortcuts).
- **Service Worker:** `web/sw.js`. Strategie:
- Navigationen: network-first, bei fehlender Verbindung `offline.html`.
- Statische Assets: stale-while-revalidate (schnell, aktualisiert im
Hintergrund).
- Manifest/Offline-Seite: cache-first.
- Authentifizierte HTML-Seiten, Formulare und API-Antworten werden bewusst
nicht gecacht. Die App zeigt online immer den aktuellen Buchungsstand.
- Der Service Worker wird in `web/assets/app.js` registriert; die Icons liegen
als PNG (192/512, maskable) und SVG vor, dazu ein Apple-Touch-Icon.
- Bei Änderungen an CSS/JS `DIC_ASSET_VERSION` in `app/util.php` und `VERSION`
in `web/sw.js` erhöhen. Der Deploy lädt die Dateien per FTP hoch; Apache
liefert `sw.js` mit `no-cache` aus.
## Betrieb
- Installation: `install.php?token=…` legt Schema und Grunddaten an, erzeugt den

View file

@ -21,12 +21,21 @@ $navActive = static function (string $area) use ($path): string {
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="theme-color" content="#196abc">
<meta name="color-scheme" content="light">
<meta name="csrf-token" content="<?= e(csrf_token()) ?>">
<meta name="sw-url" content="<?= e(url('/sw.js')) ?>">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<meta name="apple-mobile-web-app-title" content="Drink it cold">
<meta name="application-name" content="Drink it cold">
<title><?= e($title) ?> · Drink it cold</title>
<link rel="manifest" href="<?= e(url('/manifest.webmanifest')) ?>">
<link rel="icon" type="image/svg+xml" href="<?= e(asset('favicon.svg')) ?>">
<link rel="apple-touch-icon" href="<?= e(asset('logo-mark.svg')) ?>">
<link rel="icon" type="image/png" sizes="32x32" href="<?= e(asset('icons/icon-32.png')) ?>">
<link rel="apple-touch-icon" sizes="180x180" href="<?= e(asset('icons/apple-touch-icon-180.png')) ?>">
<link rel="preload" as="font" type="font/woff2" href="<?= e(asset('fonts/manrope-latin.woff2')) ?>" crossorigin>
<link rel="preload" as="font" type="font/woff2" href="<?= e(asset('fonts/inter-latin.woff2')) ?>" crossorigin>
<link rel="stylesheet" href="<?= e(asset('app.css')) ?>">
@ -61,6 +70,7 @@ $navActive = static function (string $area) use ($path): string {
<symbol id="i-alert" viewBox="0 0 24 24"><path d="M12 3.5 2.5 20.5h19z"/><path d="M12 9.5v5M12 17.6v.4"/></symbol>
<symbol id="i-snow" viewBox="0 0 24 24"><path d="M12 2v20M4.5 6.8l15 10.4M19.5 6.8 4.5 17.2M12 6.4 9.6 4M12 6.4 14.4 4M12 17.6 9.6 20M12 17.6l2.4 2.4"/></symbol>
<symbol id="i-sun" viewBox="0 0 24 24"><circle cx="12" cy="12" r="4"/><path d="M12 2v3M12 19v3M2 12h3M19 12h3M4.9 4.9 7 7M17 17l2.1 2.1M19.1 4.9 17 7M7 17l-2.1 2.1"/></symbol>
<symbol id="i-download" viewBox="0 0 24 24"><path d="M12 3v12M7 10l5 5 5-5"/><path d="M5 20h14"/></symbol>
</defs>
</svg>
@ -108,6 +118,7 @@ $navActive = static function (string $area) use ($path): string {
<p class="user-menu__who"><strong><?= e($user['first_name'] . ' ' . $user['last_name']) ?></strong>
<span><?= $isAdmin ? 'Administrator' : 'Mitarbeiter' ?></span></p>
<a href="<?= e(url('/account')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-user"/></svg>Mein Konto</a>
<button type="button" class="menu-button" data-install-app hidden><svg class="ico" aria-hidden="true"><use href="#i-download"/></svg>App installieren</button>
<?php if ($isAdmin): ?>
<a href="<?= e(url('/admin/users')) ?>"><svg class="ico" aria-hidden="true"><use href="#i-users"/></svg>Benutzerverwaltung</a>
<?php endif; ?>

View file

@ -9,14 +9,24 @@
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="theme-color" content="#196abc">
<meta name="color-scheme" content="light">
<meta name="sw-url" content="<?= e(url('/sw.js')) ?>">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<meta name="apple-mobile-web-app-title" content="Drink it cold">
<meta name="application-name" content="Drink it cold">
<title>Anmelden · Drink it cold</title>
<link rel="manifest" href="<?= e(url('/manifest.webmanifest')) ?>">
<link rel="icon" type="image/svg+xml" href="<?= e(asset('favicon.svg')) ?>">
<link rel="apple-touch-icon" href="<?= e(asset('logo-mark.svg')) ?>">
<link rel="icon" type="image/png" sizes="32x32" href="<?= e(asset('icons/icon-32.png')) ?>">
<link rel="apple-touch-icon" sizes="180x180" href="<?= e(asset('icons/apple-touch-icon-180.png')) ?>">
<link rel="preload" as="image" href="<?= e(asset('img/hero-1280.webp')) ?>" imagesrcset="<?= e(asset('img/hero-800.webp')) ?> 800w, <?= e(asset('img/hero-1280.webp')) ?> 1280w" imagesizes="50vw">
<link rel="preload" as="font" type="font/woff2" href="<?= e(asset('fonts/manrope-latin.woff2')) ?>" crossorigin>
<link rel="stylesheet" href="<?= e(asset('app.css')) ?>">
<script src="<?= e(asset('app.js')) ?>" defer></script>
</head>
<body class="auth-page">
<div class="auth-shell">

View file

@ -6,6 +6,10 @@ Options -Indexes
DirectoryIndex index.php index.html
AddDefaultCharset UTF-8
<IfModule mod_mime.c>
AddType application/manifest+json .webmanifest
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
@ -32,6 +36,13 @@ AddDefaultCharset UTF-8
<FilesMatch "\.(css|js|svg|png|jpg|jpeg|webp|ico|woff2)$">
Header set Cache-Control "public, max-age=604800"
</FilesMatch>
<FilesMatch "^sw\.js$">
Header set Cache-Control "no-cache, no-store, must-revalidate"
Header set Service-Worker-Allowed "/"
</FilesMatch>
<FilesMatch "^(manifest\.webmanifest|offline\.html)$">
Header set Cache-Control "public, max-age=3600"
</FilesMatch>
</IfModule>
<FilesMatch "^(\.env|\.git.*|composer\..*)$">

View file

@ -778,6 +778,18 @@ a .ico, button .ico { pointer-events: none; }
.error-card h1 { margin-bottom: 8px; }
.error-card p { color: var(--muted); margin-bottom: 18px; }
/* --------------------------------------------------------------- PWA */
@supports (padding: env(safe-area-inset-top)) {
.topbar { padding-top: env(safe-area-inset-top); }
.page { padding-bottom: max(48px, calc(48px + env(safe-area-inset-bottom))); }
.auth-panel { padding-bottom: max(clamp(22px, 4vw, 56px), calc(22px + env(safe-area-inset-bottom))); }
}
@media (display-mode: standalone) {
.footer { padding-bottom: calc(30px + env(safe-area-inset-bottom)); }
.auth-foot { bottom: calc(22px + env(safe-area-inset-bottom)); }
}
/* --------------------------------------------------------------- Responsive */
@media (max-width: 1240px) {
.dash-grid { grid-template-columns: 1fr; }

View file

@ -3,7 +3,48 @@
'use strict';
const csrf = document.querySelector('meta[name="csrf-token"]')?.content || '';
const swMeta = document.querySelector('meta[name="sw-url"]');
let toastTimer = 0;
let installPrompt = null;
/* --------------------------------------------------------------- PWA */
const registerServiceWorker = () => {
if (!('serviceWorker' in navigator) || !swMeta) return;
navigator.serviceWorker.register(swMeta.content).catch(() => {
/* Installation ist optional; die App funktioniert auch ohne SW. */
});
};
if (document.readyState === 'complete') {
registerServiceWorker();
} else {
window.addEventListener('load', registerServiceWorker, { once: true });
}
window.addEventListener('beforeinstallprompt', (event) => {
event.preventDefault();
installPrompt = event;
document.querySelectorAll('[data-install-app]').forEach((button) => { button.hidden = false; });
});
window.addEventListener('appinstalled', () => {
installPrompt = null;
document.querySelectorAll('[data-install-app]').forEach((button) => { button.hidden = true; });
toast('Die App wurde installiert.');
});
document.addEventListener('click', async (event) => {
const button = event.target.closest('[data-install-app]');
if (!button || !installPrompt) return;
const prompt = installPrompt;
installPrompt = null;
button.hidden = true;
try {
prompt.prompt();
await prompt.userChoice;
} catch (error) {
/* Der Browser kann die Installation trotzdem abgelehnt haben. */
}
});
const toast = (message, isError = false) => {
const el = document.getElementById('toast');

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View file

@ -0,0 +1,47 @@
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512">
<rect width="512" height="512" fill="#196abc"/>
<g transform="translate(256 256) scale(0.72)" fill="none" stroke="#ffffff" stroke-width="22" stroke-linecap="round" stroke-linejoin="round">
<g transform="rotate(0)">
<path d="M0 -158 L0 0"/>
<path d="M0 -92 L-42 -134"/>
<path d="M0 -92 L42 -134"/>
<path d="M0 -136 L-30 -166"/>
<path d="M0 -136 L30 -166"/>
</g>
<g transform="rotate(60)">
<path d="M0 -158 L0 0"/>
<path d="M0 -92 L-42 -134"/>
<path d="M0 -92 L42 -134"/>
<path d="M0 -136 L-30 -166"/>
<path d="M0 -136 L30 -166"/>
</g>
<g transform="rotate(120)">
<path d="M0 -158 L0 0"/>
<path d="M0 -92 L-42 -134"/>
<path d="M0 -92 L42 -134"/>
<path d="M0 -136 L-30 -166"/>
<path d="M0 -136 L30 -166"/>
</g>
<g transform="rotate(180)">
<path d="M0 -158 L0 0"/>
<path d="M0 -92 L-42 -134"/>
<path d="M0 -92 L42 -134"/>
<path d="M0 -136 L-30 -166"/>
<path d="M0 -136 L30 -166"/>
</g>
<g transform="rotate(240)">
<path d="M0 -158 L0 0"/>
<path d="M0 -92 L-42 -134"/>
<path d="M0 -92 L42 -134"/>
<path d="M0 -136 L-30 -166"/>
<path d="M0 -136 L30 -166"/>
</g>
<g transform="rotate(300)">
<path d="M0 -158 L0 0"/>
<path d="M0 -92 L-42 -134"/>
<path d="M0 -92 L42 -134"/>
<path d="M0 -136 L-30 -166"/>
<path d="M0 -136 L30 -166"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

47
web/assets/icons/icon.svg Normal file
View file

@ -0,0 +1,47 @@
<svg xmlns="http://www.w3.org/2000/svg" width="512" height="512" viewBox="0 0 512 512">
<rect width="512" height="512" rx="112" fill="#196abc"/>
<g transform="translate(256 256)" fill="none" stroke="#ffffff" stroke-width="22" stroke-linecap="round" stroke-linejoin="round">
<g transform="rotate(0)">
<path d="M0 -158 L0 0"/>
<path d="M0 -92 L-42 -134"/>
<path d="M0 -92 L42 -134"/>
<path d="M0 -136 L-30 -166"/>
<path d="M0 -136 L30 -166"/>
</g>
<g transform="rotate(60)">
<path d="M0 -158 L0 0"/>
<path d="M0 -92 L-42 -134"/>
<path d="M0 -92 L42 -134"/>
<path d="M0 -136 L-30 -166"/>
<path d="M0 -136 L30 -166"/>
</g>
<g transform="rotate(120)">
<path d="M0 -158 L0 0"/>
<path d="M0 -92 L-42 -134"/>
<path d="M0 -92 L42 -134"/>
<path d="M0 -136 L-30 -166"/>
<path d="M0 -136 L30 -166"/>
</g>
<g transform="rotate(180)">
<path d="M0 -158 L0 0"/>
<path d="M0 -92 L-42 -134"/>
<path d="M0 -92 L42 -134"/>
<path d="M0 -136 L-30 -166"/>
<path d="M0 -136 L30 -166"/>
</g>
<g transform="rotate(240)">
<path d="M0 -158 L0 0"/>
<path d="M0 -92 L-42 -134"/>
<path d="M0 -92 L42 -134"/>
<path d="M0 -136 L-30 -166"/>
<path d="M0 -136 L30 -166"/>
</g>
<g transform="rotate(300)">
<path d="M0 -158 L0 0"/>
<path d="M0 -92 L-42 -134"/>
<path d="M0 -92 L42 -134"/>
<path d="M0 -136 L-30 -166"/>
<path d="M0 -136 L30 -166"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

88
web/manifest.webmanifest Normal file
View file

@ -0,0 +1,88 @@
{
"id": "/",
"name": "Drink it cold – Terminplanung",
"short_name": "Drink it cold",
"description": "Kühlanhänger-Verleih: Buchungen, Kalender, Übergaben und automatische Erinnerungen für das Team.",
"lang": "de",
"dir": "ltr",
"start_url": "/?source=pwa",
"scope": "/",
"display": "standalone",
"background_color": "#f4f9fe",
"theme_color": "#196abc",
"categories": ["business", "productivity"],
"prefer_related_applications": false,
"icons": [
{
"src": "/assets/icons/icon-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any"
},
{
"src": "/assets/icons/icon-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any"
},
{
"src": "/assets/icons/icon-maskable-192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "/assets/icons/icon-maskable-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
},
{
"src": "/assets/icons/icon.svg",
"sizes": "any",
"type": "image/svg+xml",
"purpose": "any"
}
],
"shortcuts": [
{
"name": "Kalender",
"short_name": "Kalender",
"description": "Wochenkalender aller acht Anhänger öffnen",
"url": "/calendar?view=week",
"icons": [
{
"src": "/assets/icons/icon-192.png",
"sizes": "192x192",
"type": "image/png"
}
]
},
{
"name": "Neue Buchung",
"short_name": "Buchung",
"description": "Mietzeitraum und Kundendaten erfassen",
"url": "/bookings/new",
"icons": [
{
"src": "/assets/icons/icon-192.png",
"sizes": "192x192",
"type": "image/png"
}
]
},
{
"name": "Erinnerungen",
"short_name": "Erinnerungen",
"description": "Fällige Übergaben und Rücknahmen anzeigen",
"url": "/reminders",
"icons": [
{
"src": "/assets/icons/icon-192.png",
"sizes": "192x192",
"type": "image/png"
}
]
}
]
}

26
web/offline.html Normal file
View file

@ -0,0 +1,26 @@
<!doctype html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
<meta name="theme-color" content="#196abc">
<meta name="robots" content="noindex, nofollow">
<title>Offline · Drink it cold</title>
<link rel="manifest" href="/manifest.webmanifest">
<link rel="icon" type="image/svg+xml" href="/assets/favicon.svg">
<link rel="apple-touch-icon" sizes="180x180" href="/assets/icons/apple-touch-icon-180.png">
<link rel="stylesheet" href="/assets/app.css">
</head>
<body class="error-page">
<main class="error-card">
<img src="/assets/logo-mark.svg" alt="" width="72" height="52">
<p class="eyebrow">Drink it cold · Terminplanung</p>
<h1>Keine Verbindung</h1>
<p>Die Terminplanung braucht eine Internetverbindung, damit alle Mitarbeiter denselben aktuellen Stand sehen. Gerade können keine Buchungen geladen werden.</p>
<p>
<a class="btn primary" href="/">Erneut versuchen</a>
</p>
<p class="muted small">Sobald die Verbindung wieder da ist, steht der aktuelle Kalender sofort zur Verfügung.</p>
</main>
</body>
</html>

140
web/sw.js Normal file
View file

@ -0,0 +1,140 @@
/* Drink it cold – Service Worker
*
* Die App braucht für aktuelle Buchungsdaten eine Verbindung. Der Service
* Worker macht sie installierbar und beschleunigt die statischen Assets.
* Authentifizierte HTML-Seiten und API-Antworten werden bewusst NICHT
* zwischengespeichert, damit niemand veraltete Buchungen sieht.
*/
const VERSION = 'dic-v2';
const CACHE = VERSION;
const BASE = new URL(self.registration.scope).pathname.replace(/\/$/, '');
const PRECACHE = [
'/manifest.webmanifest',
'/offline.html',
'/assets/app.css',
'/assets/app.js',
'/assets/logo-mark.svg',
'/assets/favicon.svg',
'/assets/fonts/manrope-latin.woff2',
'/assets/fonts/inter-latin.woff2',
'/assets/img/hero-800.webp',
'/assets/img/hero-1280.webp',
'/assets/icons/icon-192.png',
'/assets/icons/icon-512.png',
'/assets/icons/icon-maskable-192.png',
'/assets/icons/icon-maskable-512.png',
'/assets/icons/apple-touch-icon-180.png'
].map((path) => `${BASE}${path}`);
const offlineUrl = `${BASE}/offline.html`;
const assetPrefix = `${BASE}/assets/`;
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE)
.then((cache) => cache.addAll(PRECACHE))
.then(() => self.skipWaiting())
);
});
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys()
.then((keys) => Promise.all(
keys
.filter((key) => key.startsWith('dic-') && key !== CACHE)
.map((key) => caches.delete(key))
))
.then(() => self.clients.claim())
);
});
function cacheKey(request) {
const url = new URL(request.url);
url.search = '';
return url.toString();
}
async function cacheFirst(event, request) {
const cache = await caches.open(CACHE);
const cached = await cache.match(request, { ignoreSearch: true });
const network = fetch(request)
.then((response) => {
if (response && response.ok) {
cache.put(cacheKey(request), response.clone());
}
return response;
})
.catch(() => null);
if (cached) {
event.waitUntil(network);
return cached;
}
return (await network) || new Response('', { status: 504, statusText: 'Offline' });
}
async function staleWhileRevalidate(event, request) {
const cache = await caches.open(CACHE);
const cached = await cache.match(request, { ignoreSearch: true });
const network = fetch(request)
.then((response) => {
if (response && response.ok) {
cache.put(cacheKey(request), response.clone());
}
return response;
})
.catch(() => null);
if (cached) {
event.waitUntil(network);
return cached;
}
return (await network) || new Response('', { status: 504, statusText: 'Offline' });
}
async function navigate(request) {
try {
return await fetch(request);
} catch (error) {
const cache = await caches.open(CACHE);
const offline = await cache.match(offlineUrl);
if (offline) {
return offline;
}
return new Response(
'<!doctype html><html lang="de"><meta charset="utf-8"><title>Offline</title>'
+ '<body style="font-family:system-ui;padding:2rem;background:#f4f9fe;color:#0e1b26">'
+ '<h1>Keine Verbindung</h1><p>Bitte die Internetverbindung prüfen und erneut versuchen.</p></body></html>',
{ status: 503, headers: { 'Content-Type': 'text/html; charset=utf-8' } }
);
}
}
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) {
return;
}
if (request.mode === 'navigate') {
event.respondWith(navigate(request));
return;
}
if (url.pathname.startsWith(assetPrefix)) {
event.respondWith(staleWhileRevalidate(event, request));
return;
}
if (url.pathname === `${BASE}/manifest.webmanifest` || url.pathname === offlineUrl) {
event.respondWith(cacheFirst(event, request));
}
});