From 153f15b1c0b7c805ff4d39fb3b9091f922ea25c8 Mon Sep 17 00:00:00 2001 From: Tobi Date: Tue, 9 Apr 2024 10:06:44 +0200 Subject: [PATCH] debugging PWA --- index.html | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 61b8e4a..6a14c28 100644 --- a/index.html +++ b/index.html @@ -96,14 +96,30 @@ padding: 20px; } + + -
+ - + + +

Exchange Rate Calculator

@@ -185,20 +201,27 @@ let deferredPrompt; window.addEventListener('beforeinstallprompt', (event) => { + // Prevent the default installation prompt event.preventDefault(); + // Stash the event so it can be triggered later deferredPrompt = event; + // Show installation instructions only if app is not already installed if (!window.matchMedia('(display-mode: standalone)').matches) { - document.getElementById('install-instructions').style.display = 'block'; + document.getElementById('install-instructions').classList.add('show'); + document.getElementById('installButton').style.display = 'block'; } }); function installApp() { + // Show the installation prompt when the user clicks the button if (deferredPrompt) { deferredPrompt.prompt(); deferredPrompt.userChoice.then((choiceResult) => { if (choiceResult.outcome === 'accepted') { console.log('User accepted the A2HS prompt'); - document.getElementById('install-instructions').style.display = 'none'; + // App installed, hide installation instructions + document.getElementById('install-instructions').classList.remove('show'); + document.getElementById('installButton').style.display = 'none'; } deferredPrompt = null; }); @@ -206,6 +229,7 @@ } +