-
-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add PWA caching and cache updater (#1421)
Co-authored-by: th33xitus <domwil1091+github@gmail.com>
- Loading branch information
Showing
6 changed files
with
90 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<template> | ||
<v-dialog v-model="showDialog" persistent max-width="400" class="mx-0"> | ||
<panel | ||
:title="$t('App.TheServiceWorker.TitleNeedUpdate')" | ||
card-class="service-worker-dialog" | ||
:margin-bottom="false"> | ||
<v-card-text> | ||
<p>{{ $t('App.TheServiceWorker.DescriptionNeedUpdate') }}</p> | ||
</v-card-text> | ||
<v-card-actions> | ||
<v-spacer /> | ||
<v-btn text color="primary" @click="update">{{ $t('App.TheServiceWorker.Update') }}</v-btn> | ||
</v-card-actions> | ||
</panel> | ||
</v-dialog> | ||
</template> | ||
<script lang="ts"> | ||
import Component from 'vue-class-component' | ||
import { Mixins } from 'vue-property-decorator' | ||
import BaseMixin from '@/components/mixins/base' | ||
@Component | ||
export default class TheServiceWorker extends Mixins(BaseMixin) { | ||
showDialog = false | ||
updateSW: ((reloadPage?: boolean | undefined) => Promise<void>) | null = null | ||
onOfflineReady() { | ||
window.console.info('PWA is offline ready') | ||
} | ||
onNeedRefresh() { | ||
window.console.warn('PWA needs to refresh') | ||
this.showDialog = true | ||
} | ||
onRegistered() { | ||
window.console.debug('PWA is registered') | ||
} | ||
onRegisterError(error: any) { | ||
window.console.error('PWA registration error:', error) | ||
} | ||
update() { | ||
this.updateSW?.(true) | ||
this.showDialog = false | ||
} | ||
async mounted() { | ||
const { registerSW } = await import('virtual:pwa-register') | ||
this.updateSW = registerSW({ | ||
immediate: true, | ||
onOfflineReady: this.onOfflineReady, | ||
onNeedRefresh: this.onNeedRefresh, | ||
onRegistered: this.onRegistered, | ||
onRegisterError: this.onRegisterError, | ||
}) | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters