File size: 858 Bytes
ea35075 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/// <reference types="vite-plugin-pwa/client" />
// #v-ifdef VITE_IS_ONLINE
import { registerSW } from 'virtual:pwa-register'
// #v-endif
import { ShowDialog } from '../../components/Dialog'
import i18n from '../../i18n'
async function PWAPopup(update: (reloadPage?: boolean) => Promise<void>) {
const result = await ShowDialog({
title: i18n.t('Updates are available, please confirm!!') ?? '',
button: i18n.t('Update') ?? '',
})
if (result === 'action') {
update(true)
}
}
export function PWACheck() {
if (import.meta.env.MODE !== 'online') return
const updateSW = registerSW({
onNeedRefresh() {
console.log('有更新,需要刷新!!')
PWAPopup(updateSW)
},
onOfflineReady() {
console.log('已经入离线模式!!')
},
})
}
|