This commit is contained in:
@@ -6,6 +6,8 @@ import {onMounted, ref} from "vue";
|
||||
import {Auth} from "@/services/auth";
|
||||
import DialogHost from "@/components/dialog/DialogHost.vue";
|
||||
import {LoginService} from "@/services/LoginService";
|
||||
import {Dialogs} from "@/services/DialogService";
|
||||
import InstallPWADialog from "@/components/dialog/InstallPWADialog.vue";
|
||||
|
||||
let showPopup = ref(false)
|
||||
let loggedIn = ref(false)
|
||||
@@ -33,6 +35,40 @@ LoginService.subject.subscribe(() => {
|
||||
showPopup.value = true
|
||||
})
|
||||
|
||||
const installEvent = ref<Event>()
|
||||
|
||||
window.addEventListener('beforeinstallprompt', (e) => {
|
||||
e.preventDefault()
|
||||
console.log("beforeinstallprompt")
|
||||
installEvent.value = e
|
||||
scheduleInstallDialog()
|
||||
})
|
||||
|
||||
function scheduleInstallDialog() {
|
||||
if (isPwa()) return
|
||||
if (localStorage.getItem('installPromptDismissed')) return
|
||||
if (!installEvent.value) return
|
||||
|
||||
Dialogs.createDialog(InstallPWADialog, {
|
||||
onPositive(dontShowAgain: boolean) {
|
||||
if (dontShowAgain) localStorage.setItem('installPromptDismissed', 'true')
|
||||
;(installEvent.value as any).prompt()
|
||||
},
|
||||
onNegative(dontShowAgain: boolean) {
|
||||
if (dontShowAgain) localStorage.setItem('installPromptDismissed', 'true')
|
||||
},
|
||||
onDismiss() {}
|
||||
}, {})
|
||||
}
|
||||
|
||||
function isPwa() {
|
||||
return window.matchMedia('(display-mode: standalone)').matches
|
||||
}
|
||||
|
||||
window.addEventListener('appinstalled', () => {
|
||||
localStorage.setItem('installPromptDismissed', 'true')
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
Reference in New Issue
Block a user