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:
@@ -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(); }
|
||||
|
||||
Reference in New Issue
Block a user