diff --git a/static/icon-192.png b/static/icon-192.png new file mode 100644 index 0000000..b2e20cc Binary files /dev/null and b/static/icon-192.png differ diff --git a/static/icon-512.png b/static/icon-512.png new file mode 100644 index 0000000..dfe1db0 Binary files /dev/null and b/static/icon-512.png differ diff --git a/static/manifest.webmanifest b/static/manifest.webmanifest index 1a4b1fd..b879b00 100644 --- a/static/manifest.webmanifest +++ b/static/manifest.webmanifest @@ -9,6 +9,9 @@ "background_color": "#f5f2ed", "theme_color": "#c84b2f", "icons": [ - { "src": "/icon.svg", "sizes": "any", "type": "image/svg+xml", "purpose": "any maskable" } + { "src": "/static/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any" }, + { "src": "/static/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any" }, + { "src": "/static/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "maskable" }, + { "src": "/icon.svg", "sizes": "any", "type": "image/svg+xml", "purpose": "any" } ] } diff --git a/static/offline.js b/static/offline.js index 0b0154d..d5b52e4 100644 --- a/static/offline.js +++ b/static/offline.js @@ -71,6 +71,38 @@ else { el.style.opacity = '0'; } } + // ---- Install ("Add to home screen") prompt ---- + var deferredPrompt = null; + function showInstall() { + if (!document.body) { document.addEventListener('DOMContentLoaded', showInstall); return; } + var b = document.getElementById('citti-install'); + if (!b) { + b = document.createElement('button'); + b.id = 'citti-install'; + b.type = 'button'; + b.textContent = '⬇ Installér app'; + b.style.cssText = 'position:fixed;left:14px;bottom:14px;z-index:9999;padding:9px 15px;' + + 'border:none;border-radius:20px;background:#1a1814;color:#fff;cursor:pointer;' + + 'font:600 13px/1 system-ui,-apple-system,sans-serif;box-shadow:0 2px 10px rgba(0,0,0,.25)'; + b.addEventListener('click', function () { + if (!deferredPrompt) return; + deferredPrompt.prompt(); + deferredPrompt.userChoice.finally(function () { deferredPrompt = null; b.remove(); }); + }); + document.body.appendChild(b); + } + } + window.addEventListener('beforeinstallprompt', function (e) { + e.preventDefault(); // keep the event so we can trigger it from our button + deferredPrompt = e; + showInstall(); + }); + window.addEventListener('appinstalled', function () { + deferredPrompt = null; + var b = document.getElementById('citti-install'); + if (b) b.remove(); + }); + window.addEventListener('online', function () { render(); flush(); }); window.addEventListener('offline', render); if (document.readyState !== 'loading') { render(); flush(); } diff --git a/static/sw.js b/static/sw.js index af7d60e..847f7db 100644 --- a/static/sw.js +++ b/static/sw.js @@ -1,8 +1,9 @@ // citti service worker — offline shell + asset caching. // Pages: network-first (fresh when online, cached copy in the store). // Assets: cache-first. POSTs are never touched here — the page queues them. -const CACHE = 'citti-v1'; -const CORE = ['/', '/tilbud', '/koeb-nu', '/offline.js', '/manifest.webmanifest', '/icon.svg']; +const CACHE = 'citti-v2'; +const CORE = ['/', '/tilbud', '/koeb-nu', '/offline.js', '/manifest.webmanifest', + '/icon.svg', '/static/icon-192.png', '/static/icon-512.png']; self.addEventListener('install', (e) => { e.waitUntil(