feat: add install pwa button

This commit is contained in:
YunYouJun
2023-07-30 14:03:58 +08:00
parent 7fd788a29b
commit cad0bc887f
4 changed files with 19 additions and 6 deletions

View File

@@ -1,7 +1,8 @@
import { isClient } from '@vueuse/core'
/**
* https://web.dev/customize-install/#detect-install
* - https://web.dev/customize-install/#detect-install
* - [Trigger installation from your PWA](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps/How_to/Trigger_install_prompt)
* @returns
*/
export function installPrompt() {
@@ -12,9 +13,10 @@ export function installPrompt() {
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent the mini-infobar from appearing on mobile
// e.preventDefault()
e.preventDefault()
// Stash the event so it can be triggered later.
app.deferredPrompt = e
// Update UI notify the user they can install the PWA
// showInstallPromotion()
// Optionally, send analytics event that PWA install promo was shown.