Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reload prompt for updating service worker #2574

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,23 @@
</router-view>
</div>

<ReloadPrompt />
<FooterComponent />
</div>
</template>

<script>
import NavBar from "./components/NavBar.vue";
import FooterComponent from "./components/FooterComponent.vue";
import ReloadPrompt from "./components/ReloadPrompt.vue";

const darkModePreference = window.matchMedia("(prefers-color-scheme: dark)");

export default {
components: {
NavBar,
FooterComponent,
ReloadPrompt,
},
data() {
return {
Expand Down
33 changes: 33 additions & 0 deletions src/components/ReloadPrompt.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<script setup>
import { useRegisterSW } from "virtual:pwa-register/vue";

const { offlineReady, needRefresh, updateServiceWorker } = useRegisterSW();

const close = async () => {
offlineReady.value = false;
needRefresh.value = false;
};
</script>

<template>
<div v-if="offlineReady || needRefresh" class="pwa-toast" role="alert">
<div class="message">
<span v-if="offlineReady"> App ready to work offline </span>
<span v-else> New content available, click on reload button to update. </span>
</div>
<button v-if="needRefresh" @click="updateServiceWorker()">Reload</button>
<button @click="close">Close</button>
</div>
Comment on lines +13 to +20
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copied this from the documentation, CSS needs to be updated for various themes, and these strings need to be localized.

</template>

<style>
.pwa-toast {
@apply fixed right-0 bottom-0 m-4 p-3 border border-gray-500 rounded shadow bg-white text-gray-700;
}
.pwa-toast .message {
@apply margin-bottom-2;
}
.pwa-toast button {
@apply border border-solid border-gray-500 rounded px-2 py-1;
}
</style>
2 changes: 0 additions & 2 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ import "uno.css";

const timeAgo = new TimeAgo("en-US");

import("./registerServiceWorker");

const mixin = {
methods: {
timeFormat: function (duration) {
Expand Down
7 changes: 0 additions & 7 deletions src/registerServiceWorker.js

This file was deleted.

2 changes: 1 addition & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default defineConfig({
targets: ["defaults", "not IE 11"],
}),
VitePWA({
registerType: "autoUpdate",
registerType: "prompt",
workbox: {
globPatterns: ["**/*.{js,css,html,ico,svg,png}", "manifest.webmanifest"],
globIgnores: ["**/*-legacy-*.js"],
Expand Down