Skip to content

Commit

Permalink
hide pwa button if not supported event
Browse files Browse the repository at this point in the history
  • Loading branch information
userXinos committed Jan 14, 2024
1 parent 87c0d3d commit ad8a27c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
5 changes: 1 addition & 4 deletions src/components/InstallPWA.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<div>
<div v-if="error != 'NOT_SUPPORTED'">
<div
class="button"
@click="isOpenModal = true"
Expand Down Expand Up @@ -35,9 +35,6 @@
<span v-if="error == 'NOT_PROVIDED'">
{{ $t('INSTALL_PWA_ERR_NOT_PROVIDE') }}
</span>
<span v-if="error == 'NOT_SUPPORTED'">
{{ $t('INSTALL_PWA_ERR_NOT_SUPPORTED') }}
</span>
<span v-if="error == 'INSTALLED'">
{{ $t('TID_ADD_MODULE_DLG_ALREADY_INSTALLED') }}
</span>
Expand Down
12 changes: 7 additions & 5 deletions src/composables/appPWA.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ export default function appPWA() {
}

onMounted(() => {
window.addEventListener('beforeinstallprompt', onBeforeinstallprompt);
window.addEventListener('appinstalled', onAppinstalled);
if (error.value == 'NOT_PROVIDED') {
window.addEventListener('beforeinstallprompt', onBeforeinstallprompt);
window.addEventListener('appinstalled', onAppinstalled);
}
});
onUnmounted(() => {
window.removeEventListener('beforeinstallprompt', onBeforeinstallprompt);
Expand All @@ -45,14 +47,14 @@ export default function appPWA() {
error.value = 'INSTALLED';
deferredPrompt.value = undefined;
}
async function install(): BeforeInstallPromptEvent['userChoice'] {
async function install(): Promise<BeforeInstallPromptEvent['userChoice']|undefined> {
if (deferredPrompt.value) {
deferredPrompt.value.prompt();

const { outcome } = await deferredPrompt.value.userChoice;
const userChoice = await deferredPrompt.value.userChoice;
deferredPrompt.value = undefined;

return outcome;
return userChoice;
}
}
}

0 comments on commit ad8a27c

Please sign in to comment.