/** * install-app.js — handles the "Installeer app" button in the footer. * * Behavior: * - Hides itself if the user is already running the site as an installed PWA * (display-mode: standalone) or iOS web-app. * - On click, opens a modal with platform-specific instructions: * iOS → "Voeg toe aan beginscherm" via Safari share sheet * Android → choice between PWA install (1-tap if available) and APK download * Desktop → instructions for Chrome/Edge install icon, or native prompt if available * - Listens for `beforeinstallprompt` (Android Chrome / desktop Chromium) and * deferreds it so the modal's "Install as PWA" button can fire it. * * Markup contract: `; document.body.appendChild(m); const close = () => m.remove(); m.querySelector('.install-modal-backdrop').addEventListener('click', close); m.querySelector('[data-close]').addEventListener('click', close); document.addEventListener('keydown', function onEsc(e) { if (e.key === 'Escape') { close(); document.removeEventListener('keydown', onEsc); } }); // If a [data-install-pwa] button is in the modal AND a deferredPrompt is // available: clicking triggers the native install dialog. const pwaBtn = m.querySelector('[data-install-pwa]'); if (pwaBtn) { pwaBtn.addEventListener('click', () => { if (!deferredPrompt) { close(); return; } deferredPrompt.prompt(); deferredPrompt.userChoice.finally(() => { deferredPrompt = null; close(); }); }); } } function iosInstructions() { showModal(`

📲 Installeer op iOS

Om deze site als app op je home-scherm te zetten:

  1. Tik op het deel-icoon onderaan in Safari
  2. Scroll tot je "Voeg toe aan beginscherm" ziet (soms achter "Meer…")
  3. Geef de app eventueel een naam en tik op Voeg toe

⚠️ Werkt alleen in Safari — niet in Chrome op iOS (Apple-beleid).

`); } function androidInstructions() { const nativeLine = deferredPrompt ? `` : `

Open deze site in Chrome en kies in het ⋮-menu → "App installeren" (of "Aan beginscherm toevoegen").

`; const apkBlock = apkUrl ? `

🤖 Optie B — APK (native Android-app)

Voordelen
  • Echte app in app-lade, naast WhatsApp/Gmail
  • Beste achtergrond-audio ondersteuning
  • Lock-screen controls werken optimaal
  • Blijft geïnstalleerd ongeacht browser-cache
Nadelen
  • Moet eenmalig "onbekende bronnen" toestaan
  • Geen auto-updates — nieuwe versie = APK opnieuw downloaden
  • Browser toont beveiligings-waarschuwing bij install
  • Alleen Android (Android 5+ / API 21+)
Download APK
  1. Tik op de gedownloade APK
  2. Sta eenmalig "installeren van onbekende bronnen" toe voor je browser
  3. Tik Installeer in de popup
  4. Open de app vanuit je app-lade
` : ''; showModal(`

🤖 Installeer op Android

Twee manieren. Kies wat bij je past:

📱 Optie A — Home-screen shortcut (PWA)

Voordelen
  • Instant — geen download of toestemmingen
  • Updates automatisch bij elke site-wijziging
  • Geen beveiligings-waarschuwing
  • Minder opslagruimte op je telefoon
Nadelen
  • Vereist Chrome als browser
  • Audio-in-achtergrond iets minder robuust dan native
  • Kan verdwijnen als je browser-data wist
${nativeLine}
${apkBlock}

💡 Weet je niet wat te kiezen? Begin met Optie A (shortcut). Te beperkt? Ga dan voor de APK.

`); } function desktopInstructions() { if (deferredPrompt) { deferredPrompt.prompt(); deferredPrompt.userChoice.finally(() => { deferredPrompt = null; }); return; } showModal(`

💻 Installeer op desktop

In Chrome, Edge of een andere Chromium-browser:

  1. Zoek het installeer-icoon in de adresbalk
  2. Klik erop en bevestig

Firefox/Safari desktop ondersteunen PWA-install niet — gebruik een bookmark.

`); } btn.addEventListener('click', () => { if (isIOS) return iosInstructions(); if (isAndroid) return androidInstructions(); return desktopInstructions(); }); })();