Feat: PWA-Implementierung - Offline-Funktionalität hinzugefügt

This commit is contained in:
2025-03-18 16:16:47 +01:00
parent 35645fc671
commit 4c69478fa8
5 changed files with 200 additions and 1 deletions

28
static/manifest.json Normal file
View File

@@ -0,0 +1,28 @@
{
"name": "MEDI Kunden",
"short_name": "MEDI",
"description": "MEDI Kundenverwaltung - Offline-fähige PWA",
"start_url": "/",
"display": "standalone",
"background_color": "#ffffff",
"theme_color": "#4CAF50",
"orientation": "portrait",
"icons": [
{
"src": "/static/images/icon-192x192.png",
"sizes": "192x192",
"type": "image/png",
"purpose": "any maskable"
},
{
"src": "/static/images/icon-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any maskable"
}
],
"categories": ["business", "productivity"],
"lang": "de-DE",
"dir": "ltr",
"prefer_related_applications": false
}

75
static/sw.js Normal file
View File

@@ -0,0 +1,75 @@
const CACHE_NAME = 'medi-customers-v1';
const urlsToCache = [
'/',
'/static/css/styles.css',
'/static/js/script.js',
'/static/images/logo.png',
'/static/images/icon-192x192.png',
'/static/images/icon-512x512.png'
];
// Installation des Service Workers
self.addEventListener('install', event => {
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
console.log('Cache geöffnet');
return cache.addAll(urlsToCache);
})
);
});
// Aktivierung des Service Workers
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheName => {
if (cacheName !== CACHE_NAME) {
console.log('Lösche alten Cache:', cacheName);
return caches.delete(cacheName);
}
})
);
})
);
});
// Fetch-Event-Handler
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
// Cache-Treffer - gib die Antwort zurück
if (response) {
return response;
}
// Kein Cache-Treffer - führe Netzwerkanfrage durch
return fetch(event.request)
.then(response => {
// Prüfe, ob wir eine gültige Antwort erhalten haben
if (!response || response.status !== 200 || response.type !== 'basic') {
return response;
}
// Klone die Antwort
const responseToCache = response.clone();
// Speichere die Antwort im Cache
caches.open(CACHE_NAME)
.then(cache => {
cache.put(event.request, responseToCache);
});
return response;
})
.catch(() => {
// Fallback für Offline-Zugriff
if (event.request.mode === 'navigate') {
return caches.match('/offline.html');
}
});
})
);
});