diff --git a/components/AutoUpdateToast.vue b/components/AutoUpdateToast.vue index 2ea9a4a..1e08e1e 100644 --- a/components/AutoUpdateToast.vue +++ b/components/AutoUpdateToast.vue @@ -7,11 +7,13 @@ const { t } = useI18n() const toast = useToast() const runtimeConfig = useRuntimeConfig() + const { dismissUpdateVersion } = storeToRefs(useConfigStore()) const interval = 5 * 60 * 1000 let lastCheck: Date | undefined const checkUpdate = async () => { + if (import.meta.dev) return if (lastCheck && new Date().getTime() - lastCheck.getTime() < interval) { return } @@ -20,7 +22,12 @@ const response = (await $fetch( 'https://deep-research.ataw.top/version.json', )) as typeof VersionMeta - if (semverGt(response.version, runtimeConfig.public.version)) { + + const hasNewVersion = semverGt( + response.version, + runtimeConfig.public.version, + ) + if (hasNewVersion && dismissUpdateVersion.value !== response.version) { toast.add({ title: t('autoUpdate.newVersionTitle', [response.version]), description: t('autoUpdate.newVersionDescription'), @@ -29,10 +36,19 @@ actions: [ { label: t('autoUpdate.refresh'), + color: 'info', onClick: () => { window.location.reload() }, }, + { + label: t('autoUpdate.dismiss'), + color: 'info', + variant: 'subtle', + onClick: () => { + dismissUpdateVersion.value = response.version + }, + }, ], }) } diff --git a/i18n/en.json b/i18n/en.json index 7aaa5a8..047c846 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -89,7 +89,8 @@ }, "autoUpdate": { "newVersionTitle": "New version available: {0}", - "newVersionDescription": "Please refresh the page to get the latest version.", - "refresh": "Refresh" + "newVersionDescription": "Note: If you are using a self-hosted version, please re-deploy to get new features and bug fixes.", + "refresh": "Refresh page", + "dismiss": "Dismiss" } } \ No newline at end of file diff --git a/i18n/zh.json b/i18n/zh.json index 886da12..031f4a4 100644 --- a/i18n/zh.json +++ b/i18n/zh.json @@ -89,7 +89,8 @@ }, "autoUpdate": { "newVersionTitle": "发现新版本:{0}", - "newVersionDescription": "请刷新页面以获取最新版本。", - "refresh": "刷新" + "newVersionDescription": "注:如果您使用的是自部署页面,请使用最新代码重新部署,即可获得最新功能和 bug 修复。", + "refresh": "刷新", + "dismiss": "忽略" } } \ No newline at end of file diff --git a/stores/config.ts b/stores/config.ts index d4ef11d..050c9c8 100644 --- a/stores/config.ts +++ b/stores/config.ts @@ -32,6 +32,11 @@ export const useConfigStore = defineStore('config', () => { provider: 'tavily', }, }) + // The version user dismissed the update notification + const dismissUpdateVersion = useLocalStorage( + 'dismiss-update-version', + '', + ) const aiApiBase = computed(() => { return config.value.ai.apiBase || 'https://api.openai.com/v1' @@ -39,5 +44,10 @@ export const useConfigStore = defineStore('config', () => { const showConfigManager = ref(false) - return { config: skipHydrate(config), aiApiBase, showConfigManager } + return { + config: skipHydrate(config), + aiApiBase, + showConfigManager, + dismissUpdateVersion: skipHydrate(dismissUpdateVersion), + } })