Listen for beforeinstallprompt to trigger 'add to home'

This commit is contained in:
Pavel Djundik 2018-06-05 15:29:43 +03:00
parent 1f604a8556
commit 0f6fd4dac5
4 changed files with 20 additions and 1 deletions

View File

@ -44,7 +44,7 @@ audio:not([controls]) {
}
[hidden],
template {
display: none;
display: none !important;
}
a {
background: transparent;

View File

@ -60,4 +60,9 @@
};
window.addEventListener("error", window.g_LoungeErrorHandler);
// Trigger early service worker registration
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("service-worker.js");
}
})();

View File

@ -8,6 +8,18 @@ const webpush = require("../webpush");
const connect = $("#connect");
const utils = require("../utils");
window.addEventListener("beforeinstallprompt", (installPromptEvent) => {
$("#webapp-install-button")
.on("click", function() {
if (installPromptEvent && installPromptEvent.prompt) {
installPromptEvent.prompt();
}
$(this).prop("hidden", true);
})
.prop("hidden", false);
});
socket.on("configuration", function(data) {
if (options.initialized) {
// Likely a reconnect, request sync for possibly missed settings.

View File

@ -15,6 +15,8 @@
<div class="row">
<div class="col-sm-12">
<h2>Native app</h2>
<button type="button" class="btn" id="webapp-install-button" hidden>Add The Lounge to Home screen</button>
<button type="button" class="btn" id="make-default-client">Open irc:// URLs with The Lounge</button>
</div>