aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--env.d.ts33
-rw-r--r--src/App.vue2
-rw-r--r--src/components/ReloadPrompt.tsx52
-rw-r--r--tsconfig.app.json2
-rw-r--r--vite.config.ts2
5 files changed, 2 insertions, 89 deletions
diff --git a/env.d.ts b/env.d.ts
index 2328006..18bdc8f 100644
--- a/env.d.ts
+++ b/env.d.ts
@@ -1,38 +1,5 @@
/// <reference types="vite/client" />
/// <reference types="vite-svg-loader" />
-/// <reference types="vite-plugin-pwa/client" />
-
-declare module 'virtual:pwa-register/vue' {
- // @ts-expect-error ignore when vue is not installed
- import type { Ref } from 'vue';
-
- export interface RegisterSWOptions {
- immediate?: boolean;
- onNeedRefresh?: () => void;
- onOfflineReady?: () => void;
- /**
- * Called only if `onRegisteredSW` is not provided.
- *
- * @deprecated Use `onRegisteredSW` instead.
- * @param registration The service worker registration if available.
- */
- onRegistered?: (registration: ServiceWorkerRegistration | undefined) => void;
- /**
- * Called once the service worker is registered (requires version `0.12.8+`).
- *
- * @param swScriptUrl The service worker script url.
- * @param registration The service worker registration if available.
- */
- onRegisteredSW?: (swScriptUrl: string, registration: ServiceWorkerRegistration | undefined) => void;
- onRegisterError?: (error: any) => void;
- }
-
- export function useRegisterSW(options?: RegisterSWOptions): {
- needRefresh: Ref<boolean>;
- offlineReady: Ref<boolean>;
- updateServiceWorker: (reloadPage?: boolean) => Promise<void>;
- };
-}
interface ImportMetaEnv {
VITE_PLAUSIBLE_API_HOST: string;
diff --git a/src/App.vue b/src/App.vue
index 10a6d0c..98199af 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -5,7 +5,6 @@ import { darkTheme, NGlobalStyle, NMessageProvider, NNotificationProvider } from
import { darkThemeOverrides, lightThemeOverrides } from './themes';
import { layouts } from './layouts';
import { useStyleStore } from './stores/style.store';
-import ReloadPrompt from './components/ReloadPrompt';
const route = useRoute();
const layout = computed(() => route?.meta?.layout ?? layouts.base);
@@ -20,7 +19,6 @@ const themeOverrides = computed(() => (styleStore.isDarkTheme ? darkThemeOverrid
<n-global-style />
<n-message-provider placement="bottom">
<n-notification-provider placement="bottom-right">
- <reload-prompt />
<component :is="layout">
<router-view />
</component>
diff --git a/src/components/ReloadPrompt.tsx b/src/components/ReloadPrompt.tsx
deleted file mode 100644
index 39ced27..0000000
--- a/src/components/ReloadPrompt.tsx
+++ /dev/null
@@ -1,52 +0,0 @@
-/* eslint-disable vue/one-component-per-file */
-import { useRegisterSW } from 'virtual:pwa-register/vue';
-import { useNotification, type NotificationReactive } from 'naive-ui';
-import { defineComponent } from 'vue';
-import { whenever } from '@vueuse/core';
-
-export default defineComponent({
- setup() {
- const notificationBuilder = useNotification();
-
- const { needRefresh, offlineReady, updateServiceWorker } = useRegisterSW();
-
- let notification: NotificationReactive | null = null;
-
- const onUpdateClicked = () => {
- if (notification) {
- notification.action = () => (
- <n-button loading type="primary" secondary>
- Reloading
- </n-button>
- );
- }
-
- updateServiceWorker();
- };
-
- whenever(
- needRefresh,
- () => {
- notification = notificationBuilder.create({
- title: 'A new version is out!',
- content: 'Update to get the latest version of it-tools',
- closable: true,
- onClose: () => {
- needRefresh.value = false;
- return true;
- },
- action: () => (
- <n-button onClick={onUpdateClicked} type="primary" secondary>
- Reload
- </n-button>
- ),
- });
- },
- { immediate: true },
- );
-
- whenever(offlineReady, () => notification?.destroy(), { immediate: true });
-
- return () => '';
- },
-});
diff --git a/tsconfig.app.json b/tsconfig.app.json
index 1a67294..45ddfca 100644
--- a/tsconfig.app.json
+++ b/tsconfig.app.json
@@ -9,6 +9,6 @@
"paths": {
"@/*": ["./src/*"]
},
- "types": ["naive-ui/volar", "vite-plugin-pwa/client"]
+ "types": ["naive-ui/volar"]
}
}
diff --git a/vite.config.ts b/vite.config.ts
index 7ba8686..c2c4d8d 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -17,7 +17,7 @@ export default defineConfig({
markdown(),
svgLoader(),
VitePWA({
- registerType: 'prompt',
+ registerType: 'autoUpdate',
strategies: 'generateSW',
manifest: {
name: 'IT Tools',