docs/.vitepress/theme/components/ReloadPrompt.vue

19dee01499aa0b8f6c370379902d303508473bf9
wotaku/docs/.vitepress/theme/components/ReloadPrompt.vue
taskylizard chore: update license0dddca8d19 1 year ago

87 lines · 2537 bytes

 1<!--
 2  All Rights Reserved
 3
 4  Copyright (c) 2025 taskylizard
 5
 6  All rights reserved. This code and its associated files may not be copied, modified, distributed, sublicensed, or used in any form, in whole or in part, without prior written permission from the copyright holder.
 7-->
 8<script setup lang="ts">
 9import { onBeforeMount, ref } from 'vue'
10
11const needRefresh = ref(false)
12
13let updateServiceWorker: (() => Promise<void>) | undefined
14
15function onNeedRefresh() {
16  needRefresh.value = true
17}
18async function close() {
19  needRefresh.value = false
20}
21
22onBeforeMount(async () => {
23  const { registerSW } = await import('virtual:pwa-register')
24  updateServiceWorker = registerSW({
25    immediate: true,
26    onNeedRefresh
27  })
28})
29</script>
30
31<template>
32  <template v-if="needRefresh">
33    <div
34      class="pwa-toast z-100 bg-$vp-c-bg b b-solid b-1px b-color-$pwa-border rounded-2 fixed bottom-0 right-0 m-6 px-6 py-4 shadow-xl"
35      role="alertdialog" aria-labelledby="pwa-message">
36      <div id="pwa-message" class="mb-3">
37        New content available, click the reload button to update.
38      </div>
39      <button type="button" class="pwa-refresh mr-2 rounded px-3 py-1" @click="updateServiceWorker?.()">
40        Reload
41      </button>
42      <button type="button" class="pwa-cancel b b-solid b-1px !b-color-$pwa-border mr-2 rounded px-3 py-1"
43        @click="close">
44        Close
45      </button>
46    </div>
47  </template>
48</template>
49
50<style scoped>
51/* PWA: Prompt for Update */
52.pwa-toast .pwa-refresh {
53  border-color: var(--vp-button-brand-border);
54  color: var(--vp-button-brand-text);
55  background-color: var(--vp-button-brand-bg);
56}
57
58.pwa-toast .pwa-refresh:hover {
59  border-color: var(--vp-button-brand-hover-border);
60  color: var(--vp-button-brand-hover-text);
61  background-color: var(--vp-button-brand-hover-bg);
62}
63
64.pwa-toast .pwa-refresh:active {
65  border-color: var(--vp-button-brand-active-border);
66  color: var(--vp-button-brand-active-text);
67  background-color: var(--vp-button-brand-active-bg);
68}
69
70.pwa-toast .pwa-cancel {
71  border-color: var(--vp-button-alt-border);
72  color: var(--vp-button-alt-text);
73  background-color: var(--vp-button-alt-bg);
74}
75
76.pwa-toast .pwa-cancel:hover {
77  border-color: var(--vp-button-alt-hover-border);
78  color: var(--vp-button-alt-hover-text);
79  background-color: var(--vp-button-alt-hover-bg);
80}
81
82.pwa-toast .pwa-cancel:active {
83  border-color: var(--vp-button-alt-active-border);
84  color: var(--vp-button-alt-active-text);
85  background-color: var(--vp-button-alt-active-bg);
86}
87</style>
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form