Skip to content

Commit

Permalink
feat(pwa): add update component
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Dec 21, 2023
1 parent 8cf1545 commit 0bff7a1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
49 changes: 49 additions & 0 deletions components/layout/PwaUpdater.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<script lang="ts" setup>
import { CloudArrowDownIcon } from '@heroicons/vue/24/solid'
</script>

<template>
<ClientOnly>
<div
v-if="$pwa?.needRefresh"
class="container mx-auto mb-4 max-w-3xl border-x border-b border-base-0/20 bg-transparent p-4"
role="alert"
>
<div class="flex items-center">
<CloudArrowDownIcon
aria-hidden="true"
class="me-2 h-6 w-6 flex-shrink-0"
/>
<span class="sr-only">Info</span>
<h3 class="text-lg font-medium text-base-content-highlight">There is a new update</h3>
</div>
<div class="mb-4 mt-2 text-sm">Refresh or click the button below to apply the update</div>
<div class="flex">
<button
class="focus-visible:focus-outline-util hover:hover-bg-util hover:hover-text-util w-full items-center rounded-md border border-base-0/20 px-3 py-2 text-center text-center text-sm font-medium text-base-content-highlight"
type="button"
@click="$pwa.updateServiceWorker()"
>
Refresh
</button>
</div>
</div>
</ClientOnly>
</template>

<style>
.pwa-toast {
@apply fixed bottom-0 right-0 z-50 m-4 rounded-md border border-base-0/20 p-3 text-left;
}
.pwa-toast .message {
@apply mb-2;
}
.pwa-toast button {
@apply mr-2 rounded-md border border-base-0/20 px-3 py-1 outline-none;
}
</style>
2 changes: 2 additions & 0 deletions layouts/default.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
/>
</div>

<PwaUpdater />

<ClientOnly>
<Toaster
:expand="true"
Expand Down
6 changes: 3 additions & 3 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export default defineNuxtConfig({

registerType: 'autoUpdate',

registerWebManifestInRouteRules: true,

manifest: {
name: 'Rule 34 App',
short_name: 'R34 App',
Expand Down Expand Up @@ -208,14 +210,12 @@ export default defineNuxtConfig({
},

client: {
installPrompt: true
installPrompt: true,
// you don't need to include this: only for testing purposes
// if enabling periodic sync for update use 1 hour or so (periodicSyncForUpdates: 3600)
// , periodicSyncForUpdates: 3600
},

selfDestroying: true,

devOptions: {
enabled: true,
suppressWarnings: true,
Expand Down

0 comments on commit 0bff7a1

Please sign in to comment.