PWA: Manifest, Service Worker, Icons und Offline-Seite
|
|
@ -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\..*)$">
|
||||
|
|
|
|||
|
|
@ -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; }
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
BIN
web/assets/icons/apple-touch-icon-180.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
BIN
web/assets/icons/icon-192.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
web/assets/icons/icon-32.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
web/assets/icons/icon-512.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
web/assets/icons/icon-maskable-192.png
Normal file
|
After Width: | Height: | Size: 9.5 KiB |
BIN
web/assets/icons/icon-maskable-512.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
47
web/assets/icons/icon-maskable.svg
Normal 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
|
|
@ -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
|
|
@ -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
|
|
@ -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
|
|
@ -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));
|
||||
}
|
||||
});
|
||||