chore: refactor cancel install logic

This commit is contained in:
userquin 2023-01-18 21:01:45 +01:00
parent b1876bc160
commit 0ce69d5399

View file

@ -76,6 +76,12 @@ export default defineNuxtPlugin(() => {
showInstallPrompt.value = false showInstallPrompt.value = false
}) })
const cancelInstall = () => {
deferredPrompt = undefined
showInstallPrompt.value = false
window.removeEventListener('beforeinstallprompt', beforeInstallPrompt)
}
const install = async () => { const install = async () => {
if (!showInstallPrompt.value || !deferredPrompt) { if (!showInstallPrompt.value || !deferredPrompt) {
showInstallPrompt.value = false showInstallPrompt.value = false
@ -87,11 +93,7 @@ export default defineNuxtPlugin(() => {
deferredPrompt.prompt() deferredPrompt.prompt()
const { outcome } = await deferredPrompt.userChoice const { outcome } = await deferredPrompt.userChoice
if (outcome === 'dismissed') if (outcome === 'dismissed')
window.removeEventListener('beforeinstallprompt', beforeInstallPrompt) cancelInstall()
}
const cancelInstall = () => {
showInstallPrompt.value = false
} }
return { return {