|
|
|
|
|
let deferredPrompt; |
|
const installButton = document.getElementById('install-button'); |
|
const installContainer = document.getElementById('install-container'); |
|
|
|
|
|
if (installContainer) { |
|
installContainer.style.display = 'none'; |
|
} |
|
|
|
|
|
window.addEventListener('beforeinstallprompt', (e) => { |
|
|
|
e.preventDefault(); |
|
|
|
deferredPrompt = e; |
|
|
|
if (installContainer) { |
|
installContainer.style.display = 'flex'; |
|
} |
|
|
|
|
|
if (installButton) { |
|
installButton.addEventListener('click', () => { |
|
|
|
installContainer.style.display = 'none'; |
|
|
|
deferredPrompt.prompt(); |
|
|
|
deferredPrompt.userChoice.then((choiceResult) => { |
|
if (choiceResult.outcome === 'accepted') { |
|
console.log('L\'utilisateur a accepté l\'installation'); |
|
} else { |
|
console.log('L\'utilisateur a refusé l\'installation'); |
|
} |
|
|
|
deferredPrompt = null; |
|
}); |
|
}); |
|
} |
|
}); |
|
|
|
|
|
window.addEventListener('appinstalled', (e) => { |
|
|
|
if (installContainer) { |
|
installContainer.style.display = 'none'; |
|
} |
|
console.log('Application installée'); |
|
}); |