Add PWA mobile attendance shortcut

This commit is contained in:
A R R R Associates
2026-07-07 18:54:37 +05:30
parent ae06956b3b
commit 2ef58ded85
8 changed files with 238 additions and 2 deletions
+42
View File
@@ -0,0 +1,42 @@
const CACHE_VERSION = 'arrr-erp-pwa-v1';
const CORE_ASSETS = [
'/manifest.webmanifest',
'/static/css/theme_tokens.css',
'/static/pwa/icons/icon-192.png',
'/static/pwa/icons/icon-512.png'
];
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_VERSION).then((cache) => cache.addAll(CORE_ASSETS)).catch(() => undefined)
);
self.skipWaiting();
});
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then((keys) => Promise.all(keys.filter((key) => key !== CACHE_VERSION).map((key) => caches.delete(key))))
);
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) return;
if (url.pathname.startsWith('/static/')) {
event.respondWith(
caches.match(request).then((cached) => cached || fetch(request).then((response) => {
const copy = response.clone();
caches.open(CACHE_VERSION).then((cache) => cache.put(request, copy)).catch(() => undefined);
return response;
}))
);
return;
}
event.respondWith(fetch(request).catch(() => caches.match('/static/css/theme_tokens.css')));
});