parent
1358283f6b
commit
68cd71344b
32
js/pwa.js
32
js/pwa.js
|
|
@ -1,6 +1,38 @@
|
||||||
const divInstall = document.getElementById('installContainer');
|
const divInstall = document.getElementById('installContainer');
|
||||||
const butInstall = document.getElementById('butInstall');
|
const butInstall = document.getElementById('butInstall');
|
||||||
|
|
||||||
|
window.addEventListener('beforeinstallprompt', (event) => {
|
||||||
|
console.log('👍', 'beforeinstallprompt', event);
|
||||||
|
// Stash the event so it can be triggered later.
|
||||||
|
window.deferredPrompt = event;
|
||||||
|
// Remove the 'hidden' class from the install button container
|
||||||
|
divInstall.classList.toggle('hidden', false);
|
||||||
|
});
|
||||||
|
|
||||||
|
butInstall.addEventListener('click', () => {
|
||||||
|
console.log('👍', 'butInstall-clicked');
|
||||||
|
const promptEvent = window.deferredPrompt;
|
||||||
|
if (!promptEvent) {
|
||||||
|
// The deferred prompt isn't available.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Show the install prompt.
|
||||||
|
promptEvent.prompt();
|
||||||
|
// Log the result
|
||||||
|
promptEvent.userChoice.then((result) => {
|
||||||
|
console.log('👍', 'userChoice', result);
|
||||||
|
// Reset the deferred prompt variable, since
|
||||||
|
// prompt() can only be called once.
|
||||||
|
window.deferredPrompt = null;
|
||||||
|
// Hide the install button.
|
||||||
|
divInstall.classList.toggle('hidden', true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('appinstalled', (event) => {
|
||||||
|
console.log('👍', 'appinstalled', event);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
/* Only register a service worker if it's supported */
|
/* Only register a service worker if it's supported */
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
|
|
|
||||||
|
|
@ -17,5 +17,6 @@
|
||||||
"theme_color": "#5755d9",
|
"theme_color": "#5755d9",
|
||||||
"background_color": "#5755d9",
|
"background_color": "#5755d9",
|
||||||
"display": "standalone",
|
"display": "standalone",
|
||||||
"start_url": "https://omegavoid.github.io/BangleApps"
|
"start_url": "/BangleApps",
|
||||||
|
"scope": "/BangleApps"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue