aboutsummaryrefslogtreecommitdiffstats
path: root/clients/www/src/lib/components/ReloadPrompt.svelte
blob: e6effbbcb4dcb60b5c0685f28e58c3a1c4ce658f (plain) (blame)
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
<script lang="ts">
  import { getToastStore } from '@skeletonlabs/skeleton'
  import { useRegisterSW } from 'virtual:pwa-register/svelte'

  const toastStore = getToastStore()

  const { updateServiceWorker } = useRegisterSW({
    onRegisteredSW(r) {
      console.log('SW Registered: ', r)
    },
    onNeedRefresh() {
      toastStore.trigger({
        message: 'A new version of the application is available.',
        autohide: false,
        action: {
          label: 'Refresh',
          response: updateServiceWorker,
        },
      })
    },
    onOfflineReady() {
      toastStore.trigger({
        background: 'variant-filled-success',
        message: 'Now ready for offline use!',
        timeout: 5000,
      })
    },
    onRegisterError(err) {
      console.error('SW Registration Error: ', err)
    },
  })
</script>