add qr-codes, share button, and pwa config toggle

This commit is contained in:
Joey Kimsey
2025-02-05 19:39:54 -05:00
parent a38d132e61
commit a6b241c7f0
10 changed files with 168 additions and 66 deletions

View File

@ -8,6 +8,61 @@
* @link https://TheTempusProject.com
* @license https://opensource.org/licenses/MIT [MIT LICENSE]
*/
let deferredPrompt;
const installPrompt = document.getElementById("install-prompt");
const installButton = document.getElementById("install-button");
const dismissButton = document.querySelector("#install-prompt .btn-close");
// Check if the user previously dismissed the prompt
if (!localStorage.getItem("pwaInstallDismissed")) {
window.addEventListener("beforeinstallprompt", (event) => {
event.preventDefault();
deferredPrompt = event;
installPrompt.classList.add("show"); // Show the prompt
});
}
// Handle Install Button Click
if ( installButton ) {
installButton.addEventListener("click", async () => {
if (deferredPrompt) {
deferredPrompt.prompt();
const { outcome } = await deferredPrompt.userChoice;
if (outcome === "dismissed") {
setInstallDismissed(); // Store that the user dismissed the prompt
}
deferredPrompt = null; // Reset prompt
installPrompt.classList.remove("show"); // Hide the prompt
}
});
}
// Handle Close Button Click
if ( dismissButton ) {
dismissButton.addEventListener("click", () => {
setInstallDismissed(); // Store that the user dismissed the prompt
});
}
// Function to remember user choice for 7 days
function setInstallDismissed() {
localStorage.setItem("pwaInstallDismissed", Date.now() + 7 * 24 * 60 * 60 * 1000);
installPrompt.classList.remove("show"); // Hide the prompt
}
// Check if the 7-day period has passed
if (localStorage.getItem("pwaInstallDismissed")) {
const dismissUntil = parseInt(localStorage.getItem("pwaInstallDismissed"), 10);
if (Date.now() < dismissUntil) {
installPrompt.classList.remove("show"); // Ensure it's hidden
} else {
localStorage.removeItem("pwaInstallDismissed"); // Reset after 7 days
}
}
/**
* Automatically selects/de-selects all check boxes associated with that field
**/