pwa upgrades

This commit is contained in:
osiu97
2026-07-08 19:07:06 +02:00
parent a321e8dd4c
commit b7effd52de
2 changed files with 39 additions and 0 deletions
+11
View File
@@ -191,6 +191,17 @@
}); });
} }
// ── PWA Install Logic ──────────────────────────────────────────
window.deferredPrompt = null;
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent automatic prompt
e.preventDefault();
window.deferredPrompt = e;
// Dispatch a custom event so sections can update their UI
window.dispatchEvent(new Event('pwa-installable'));
});
// ── Check Web Bluetooth availability ────────────────────────── // ── Check Web Bluetooth availability ──────────────────────────
if (!navigator.bluetooth) { if (!navigator.bluetooth) {
setTimeout(() => { setTimeout(() => {
+28
View File
@@ -116,9 +116,37 @@ const HomeSection = {
}; };
BLE.on('connected', update); BLE.on('connected', update);
BLE.on('disconnected', update); BLE.on('disconnected', update);
// PWA Install Logic
const pwaCard = container.querySelector('#home-pwa-install-card');
const pwaBtn = container.querySelector('#home-btn-install-pwa');
const checkPwaStatus = () => {
if (window.deferredPrompt && pwaCard) {
pwaCard.style.display = 'block';
}
};
// Check initially in case the event fired before we mounted
checkPwaStatus();
window.addEventListener('pwa-installable', checkPwaStatus);
if (pwaBtn) {
pwaBtn.addEventListener('click', async () => {
if (!window.deferredPrompt) return;
window.deferredPrompt.prompt();
const { outcome } = await window.deferredPrompt.userChoice;
console.log(`User response to the install prompt: ${outcome}`);
window.deferredPrompt = null;
pwaCard.style.display = 'none';
});
}
this._cleanup = [ this._cleanup = [
() => BLE.off('connected', update), () => BLE.off('connected', update),
() => BLE.off('disconnected', update), () => BLE.off('disconnected', update),
() => window.removeEventListener('pwa-installable', checkPwaStatus),
]; ];
}, },