|
391 | 391 | <i class="material-icons md-48">help</i> |
392 | 392 | </a> |
393 | 393 | </li> |
| 394 | + <li> |
| 395 | + <a id="installButton" class="tooltipped hidden" data-position="bottom" |
| 396 | + data-tooltip="Install App" aria-label="Install App"> |
| 397 | + <i class="material-icons md-48">file_download</i> |
| 398 | + </a> |
| 399 | + </li> |
394 | 400 | </ul> |
395 | 401 | </div> |
396 | 402 | <div class="nav-wrapper" id="aux-toolbar" style="display: none;" tabindex="-1"> |
|
568 | 574 | // Detect if running on localhost for development |
569 | 575 | const isLocalDev = window.location.hostname === "localhost" || |
570 | 576 | window.location.hostname === "127.0.0.1"; |
| 577 | + // Localhost SW is disabled to avoid caching; set allowLocalPwa to test installs. |
| 578 | + const allowLocalPwa = localStorage.getItem("allowLocalPwa") === "true"; |
571 | 579 |
|
572 | | - if (!isLocalDev) { |
| 580 | + if (!isLocalDev || allowLocalPwa) { |
573 | 581 | // Production: Register service worker for offline mode |
574 | 582 | if (navigator.serviceWorker.controller) { |
575 | 583 | console.debug( |
|
594 | 602 | console.log( |
595 | 603 | "🔥 [DEV MODE] Service worker disabled on localhost for instant code updates" |
596 | 604 | ); |
| 605 | + console.log( |
| 606 | + "Set localStorage.allowLocalPwa = 'true' to enable PWA install testing on localhost." |
| 607 | + ); |
597 | 608 | } |
598 | 609 | } |
599 | 610 | </script> |
|
604 | 615 | event.preventDefault(); // Prevent automatic browser prompt |
605 | 616 | deferredPrompt = event; |
606 | 617 |
|
607 | | - // Show your install button here |
608 | | - const divInstall = document.getElementById("installButton"); |
609 | | - if (divInstall) { |
610 | | - divInstall.classList.remove("hidden"); |
| 618 | + // Show the install button |
| 619 | + const installButton = document.getElementById("installButton"); |
| 620 | + if (installButton) { |
| 621 | + installButton.classList.remove("hidden"); |
| 622 | + } |
| 623 | + }); |
| 624 | + |
| 625 | + // Handle install button click |
| 626 | + document.addEventListener("DOMContentLoaded", function () { |
| 627 | + const installButton = document.getElementById("installButton"); |
| 628 | + if (installButton) { |
| 629 | + installButton.addEventListener("click", async function () { |
| 630 | + if (deferredPrompt) { |
| 631 | + // Show the install prompt |
| 632 | + deferredPrompt.prompt(); |
| 633 | + |
| 634 | + // Wait for user choice |
| 635 | + const { outcome } = await deferredPrompt.userChoice; |
| 636 | + console.log(`User response to the install prompt: ${outcome}`); |
| 637 | + |
| 638 | + // Clear the deferredPrompt |
| 639 | + deferredPrompt = null; |
| 640 | + |
| 641 | + // Hide the button |
| 642 | + installButton.classList.add("hidden"); |
| 643 | + } |
| 644 | + }); |
611 | 645 | } |
612 | 646 | }); |
613 | 647 | </script> |
|
803 | 837 | document.addEventListener('MSFullscreenChange', handleFullscreenChange); |
804 | 838 | </script> |
805 | 839 |
|
| 840 | + <style> |
| 841 | + #installButton.hidden { |
| 842 | + display: none !important; |
| 843 | + } |
| 844 | + </style> |
| 845 | + |
806 | 846 | <script> |
807 | 847 | document.addEventListener('DOMContentLoaded', function () { |
808 | 848 | let persistentNotification = null; |
|
0 commit comments