diff --git a/app.js b/app.js index 645e171..9842acc 100644 --- a/app.js +++ b/app.js @@ -2716,4 +2716,9 @@ init().then(() => { createPortalTunnel(); fetchGiteaData(); setInterval(fetchGiteaData, 30000); + + // Register service worker for PWA + if ('serviceWorker' in navigator) { + navigator.serviceWorker.register('/service-worker.js'); + } }); diff --git a/manifest.json b/manifest.json index 304b8fd..f23083d 100644 --- a/manifest.json +++ b/manifest.json @@ -8,9 +8,14 @@ "theme_color": "#4af0c0", "icons": [ { - "src": "/favicon.ico", - "sizes": "64x64", - "type": "image/x-icon" + "src": "/icons/icon-192x192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/icons/icon-512x512.png", + "sizes": "512x512", + "type": "image/png" } ] -} \ No newline at end of file +} diff --git a/service-worker.js b/service-worker.js new file mode 100644 index 0000000..1cdc715 --- /dev/null +++ b/service-worker.js @@ -0,0 +1,26 @@ +const CACHE_NAME = 'nexus-v1.1'; +const ASSETS_TO_CACHE = [ + '/', + '/index.html', + '/app.js', + '/style.css', + '/manifest.json', + '/icons/icon-192x192.png', + '/icons/icon-512x512.png' +]; + +self.addEventListener('install', (event) => { + event.waitUntil( + caches.open(CachedName).then(cache => { + return cache.addAll(ASSETS_TO_CACHE); + }) + ); +}); + +self.addEventListener('fetch', (event) => { + event.respondWith( + caches.match(event.request).then(response => { + return response || fetch(event.request); + }) + ); +});