diff --git a/package-lock.json b/package-lock.json index e32e2e1..4af1c75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "growing-galaxy", - "version": "0.0.1", + "version": "2.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "growing-galaxy", - "version": "0.0.1", + "version": "2.1.0", "dependencies": { "@astrojs/preact": "^4.1.3", "astro": "^5.15.5", diff --git a/package.json b/package.json index b1ca6f6..d907964 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "growing-galaxy", "type": "module", - "version": "0.0.1", + "version": "2.1.0", "scripts": { "dev": "astro dev --host", "build": "astro build", diff --git a/public/manifest.webmanifest b/public/manifest.webmanifest new file mode 100644 index 0000000..cdc7637 --- /dev/null +++ b/public/manifest.webmanifest @@ -0,0 +1,35 @@ +{ + "name": "BSC Score", + "short_name": "BSC Score", + "description": "Professional pool and billiards scoring application", + "start_url": "/", + "scope": "/", + "display": "standalone", + "orientation": "portrait", + "background_color": "#1a1a1a", + "theme_color": "#1a1a1a", + "lang": "de", + "categories": [ + "sports", + "utilities", + "productivity" + ], + "icons": [ + { + "src": "/icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/icon-512.png", + "sizes": "512x512", + "type": "image/png" + }, + { + "src": "/icon-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" + } + ] +} diff --git a/public/sw.js b/public/sw.js new file mode 100644 index 0000000..d1e122a --- /dev/null +++ b/public/sw.js @@ -0,0 +1,68 @@ +const CACHE_NAME = 'bscscore-v2.1.0'; +const APP_SHELL = [ + '/', + '/index.html', + '/manifest.webmanifest', + '/favicon.ico', + '/icon-192.png', + '/icon-512.png', +]; + +self.addEventListener('install', (event) => { + event.waitUntil( + caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL)), + ); + self.skipWaiting(); +}); + +self.addEventListener('activate', (event) => { + event.waitUntil( + caches.keys().then((keys) => + Promise.all( + keys.map((key) => { + if (key !== CACHE_NAME) { + return caches.delete(key); + } + return Promise.resolve(); + }), + ), + ), + ); + self.clients.claim(); +}); + +self.addEventListener('fetch', (event) => { + const { request } = event; + const requestUrl = new URL(request.url); + + if (request.method !== 'GET' || requestUrl.origin !== self.location.origin) { + return; + } + + if (request.mode === 'navigate') { + event.respondWith( + fetch(request) + .then((response) => { + const responseClone = response.clone(); + caches.open(CACHE_NAME).then((cache) => cache.put(request, responseClone)); + return response; + }) + .catch(() => caches.match(request).then((cached) => cached || caches.match('/'))), + ); + return; + } + + event.respondWith( + caches.match(request).then((cachedResponse) => { + if (cachedResponse) { + return cachedResponse; + } + + return fetch(request).then((networkResponse) => { + const networkClone = networkResponse.clone(); + caches.open(CACHE_NAME).then((cache) => cache.put(request, networkClone)); + return networkResponse; + }); + }), + ); +}); diff --git a/src/pages/index.astro b/src/pages/index.astro index f8e34ab..4707fa9 100644 --- a/src/pages/index.astro +++ b/src/pages/index.astro @@ -19,11 +19,14 @@ import App from "../components/App"; + + + @@ -34,5 +37,14 @@ import App from "../components/App"; --> + \ No newline at end of file