Initial commit

This commit is contained in:
TutorialsGHG
2026-04-12 21:57:21 +02:00
commit b011c7ad75
12 changed files with 2762 additions and 0 deletions

39
pwa/sw.js Normal file
View File

@@ -0,0 +1,39 @@
// NotifyPulse PWA Service Worker v3
const CACHE = 'notifypulse-v3';
const STATIC = ['/pwa/', '/pwa/index.html'];
self.addEventListener('install', e => {
e.waitUntil(
caches.open(CACHE).then(c => c.addAll(STATIC).catch(() => {}))
);
self.skipWaiting();
});
self.addEventListener('activate', e => {
e.waitUntil(
caches.keys().then(keys =>
Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)))
)
);
self.clients.claim();
});
self.addEventListener('fetch', e => {
const url = new URL(e.request.url);
// Never cache API calls
if (url.pathname.startsWith('/api/')) return;
e.respondWith(
caches.match(e.request).then(r => r || fetch(e.request).then(res => {
if (res.ok && e.request.method === 'GET') {
const clone = res.clone();
caches.open(CACHE).then(c => c.put(e.request, clone));
}
return res;
}).catch(() => caches.match('/pwa/')))
);
});
// Handle messages from main thread
self.addEventListener('message', e => {
if (e.data === 'skipWaiting') self.skipWaiting();
});