feat(pwa): installable — PNG icons + beforeinstallprompt button
Chrome's install prompt needs 192 and 512 PNG icons (SVG-only often isn't enough, especially on Android). Add them and reference them in the manifest (any + maskable). offline.js captures beforeinstallprompt and shows an 'Installér app' button that triggers the native prompt, and clears it on appinstalled. Bump SW cache to v2 so the new manifest/icons take effect.
This commit is contained in:
BIN
static/icon-192.png
Normal file
BIN
static/icon-192.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
static/icon-512.png
Normal file
BIN
static/icon-512.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.2 KiB |
@@ -9,6 +9,9 @@
|
|||||||
"background_color": "#f5f2ed",
|
"background_color": "#f5f2ed",
|
||||||
"theme_color": "#c84b2f",
|
"theme_color": "#c84b2f",
|
||||||
"icons": [
|
"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" }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,6 +71,38 @@
|
|||||||
else { el.style.opacity = '0'; }
|
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('online', function () { render(); flush(); });
|
||||||
window.addEventListener('offline', render);
|
window.addEventListener('offline', render);
|
||||||
if (document.readyState !== 'loading') { render(); flush(); }
|
if (document.readyState !== 'loading') { render(); flush(); }
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
// citti service worker — offline shell + asset caching.
|
// citti service worker — offline shell + asset caching.
|
||||||
// Pages: network-first (fresh when online, cached copy in the store).
|
// Pages: network-first (fresh when online, cached copy in the store).
|
||||||
// Assets: cache-first. POSTs are never touched here — the page queues them.
|
// Assets: cache-first. POSTs are never touched here — the page queues them.
|
||||||
const CACHE = 'citti-v1';
|
const CACHE = 'citti-v2';
|
||||||
const CORE = ['/', '/tilbud', '/koeb-nu', '/offline.js', '/manifest.webmanifest', '/icon.svg'];
|
const CORE = ['/', '/tilbud', '/koeb-nu', '/offline.js', '/manifest.webmanifest',
|
||||||
|
'/icon.svg', '/static/icon-192.png', '/static/icon-512.png'];
|
||||||
|
|
||||||
self.addEventListener('install', (e) => {
|
self.addEventListener('install', (e) => {
|
||||||
e.waitUntil(
|
e.waitUntil(
|
||||||
|
|||||||
Reference in New Issue
Block a user