Implementieren der PWA, Multi-Instanzen-Passwort-Schutz und Kassen-Löschfunktion
This commit is contained in:
BIN
static/icon-192x192.png
Normal file
BIN
static/icon-192x192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 645 B |
BIN
static/icon-512x512.png
Normal file
BIN
static/icon-512x512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.0 KiB |
21
static/manifest.json
Normal file
21
static/manifest.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "erdbeerrechner",
|
||||
"short_name": "erdbeer",
|
||||
"description": "Eine anpassbare Kassen-App.",
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#f8f9fa",
|
||||
"theme_color": "#dc3545",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/static/icon-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/static/icon-512x512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
}
|
||||
]
|
||||
}
|
||||
56
static/sw.js
Normal file
56
static/sw.js
Normal file
@@ -0,0 +1,56 @@
|
||||
const CACHE_NAME = 'erdbeerkasse-v1';
|
||||
const ASSETS_TO_CACHE = [
|
||||
'/',
|
||||
'/manifest.json',
|
||||
'/static/icon-192x192.png',
|
||||
'/static/icon-512x512.png',
|
||||
'https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css'
|
||||
];
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME)
|
||||
.then((cache) => cache.addAll(ASSETS_TO_CACHE))
|
||||
.then(() => self.skipWaiting())
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then((cacheNames) => {
|
||||
return Promise.all(
|
||||
cacheNames.map((cacheName) => {
|
||||
if (cacheName !== CACHE_NAME) {
|
||||
return caches.delete(cacheName);
|
||||
}
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
self.clients.claim();
|
||||
});
|
||||
|
||||
// Network-first strategy for dynamic instances, fallback to cache
|
||||
self.addEventListener('fetch', (event) => {
|
||||
if (event.request.method !== 'GET') {
|
||||
return;
|
||||
}
|
||||
|
||||
event.respondWith(
|
||||
fetch(event.request)
|
||||
.then((response) => {
|
||||
// Clone the response before caching if it's a valid response
|
||||
if (!response || response.status !== 200 || response.type !== 'basic') {
|
||||
return response;
|
||||
}
|
||||
|
||||
const responseToCache = response.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => {
|
||||
cache.put(event.request, responseToCache);
|
||||
});
|
||||
|
||||
return response;
|
||||
})
|
||||
.catch(() => caches.match(event.request))
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user