webapp work, push required for https

This commit is contained in:
Neale Pickett 2018-11-21 22:15:15 +00:00
parent 32e3fbad70
commit 2a2159ea3a
2 changed files with 22 additions and 21 deletions

View File

@ -16,7 +16,6 @@ headers:
</span> </span>
</div> </div>
<button id="install">Add to home screen</button>
I work in a building with no HVAC, I work in a building with no HVAC,
which means we can hear <em>everything</em> people are saying, which means we can hear <em>everything</em> people are saying,
@ -30,3 +29,5 @@ You can leave it running forever, if you like.
For those interested, For those interested,
it uses the new (in 2017), perfect for this application, it uses the new (in 2017), perfect for this application,
[Web Audio API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API) [Web Audio API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API)
<button id="install">Add to home screen</button>

View File

@ -53,17 +53,24 @@ function init() {
if ("serviceWorker" in navigator) { if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("sw.js"); navigator.serviceWorker.register("sw.js");
} }
}
// Let people add this app if (document.readyState === "loading") {
let deferredPrompt; document.addEventListener("DOMContentLoaded", init);
let installButton = document.querySelector("#install"); } else {
installButton.style.display = "none"; init();
window.addEventListener("beforeinstallprompt", e => { }
// Let people add this app
let deferredPrompt;
let installButton = document.querySelector("#install");
installButton.style.display = "none";
window.addEventListener("beforeinstallprompt", e => {
console.log(e); console.log(e);
deferredPrompt = e; deferredPrompt = e;
installButton.style.display = "block"; installButton.style.display = "block";
}); });
installButton.addEventListener("click", e => { installButton.addEventListener("click", e => {
console.log(e); console.log(e);
deferredPrompt.prompt(); deferredPrompt.prompt();
deferredPrompt.userChoice deferredPrompt.userChoice
@ -72,11 +79,4 @@ function init() {
installButton.style.display = "none"; installButton.style.display = "none";
} }
}); });
}); });
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", init);
} else {
init();
}