feat: dismiss update toast
This commit is contained in:
@ -7,11 +7,13 @@
|
|||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const runtimeConfig = useRuntimeConfig()
|
const runtimeConfig = useRuntimeConfig()
|
||||||
|
const { dismissUpdateVersion } = storeToRefs(useConfigStore())
|
||||||
|
|
||||||
const interval = 5 * 60 * 1000
|
const interval = 5 * 60 * 1000
|
||||||
let lastCheck: Date | undefined
|
let lastCheck: Date | undefined
|
||||||
|
|
||||||
const checkUpdate = async () => {
|
const checkUpdate = async () => {
|
||||||
|
if (import.meta.dev) return
|
||||||
if (lastCheck && new Date().getTime() - lastCheck.getTime() < interval) {
|
if (lastCheck && new Date().getTime() - lastCheck.getTime() < interval) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -20,7 +22,12 @@
|
|||||||
const response = (await $fetch(
|
const response = (await $fetch(
|
||||||
'https://deep-research.ataw.top/version.json',
|
'https://deep-research.ataw.top/version.json',
|
||||||
)) as typeof VersionMeta
|
)) 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({
|
toast.add({
|
||||||
title: t('autoUpdate.newVersionTitle', [response.version]),
|
title: t('autoUpdate.newVersionTitle', [response.version]),
|
||||||
description: t('autoUpdate.newVersionDescription'),
|
description: t('autoUpdate.newVersionDescription'),
|
||||||
@ -29,10 +36,19 @@
|
|||||||
actions: [
|
actions: [
|
||||||
{
|
{
|
||||||
label: t('autoUpdate.refresh'),
|
label: t('autoUpdate.refresh'),
|
||||||
|
color: 'info',
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
window.location.reload()
|
window.location.reload()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: t('autoUpdate.dismiss'),
|
||||||
|
color: 'info',
|
||||||
|
variant: 'subtle',
|
||||||
|
onClick: () => {
|
||||||
|
dismissUpdateVersion.value = response.version
|
||||||
|
},
|
||||||
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,8 @@
|
|||||||
},
|
},
|
||||||
"autoUpdate": {
|
"autoUpdate": {
|
||||||
"newVersionTitle": "New version available: {0}",
|
"newVersionTitle": "New version available: {0}",
|
||||||
"newVersionDescription": "Please refresh the page to get the latest version.",
|
"newVersionDescription": "Note: If you are using a self-hosted version, please re-deploy to get new features and bug fixes.",
|
||||||
"refresh": "Refresh"
|
"refresh": "Refresh page",
|
||||||
|
"dismiss": "Dismiss"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -89,7 +89,8 @@
|
|||||||
},
|
},
|
||||||
"autoUpdate": {
|
"autoUpdate": {
|
||||||
"newVersionTitle": "发现新版本:{0}",
|
"newVersionTitle": "发现新版本:{0}",
|
||||||
"newVersionDescription": "请刷新页面以获取最新版本。",
|
"newVersionDescription": "注:如果您使用的是自部署页面,请使用最新代码重新部署,即可获得最新功能和 bug 修复。",
|
||||||
"refresh": "刷新"
|
"refresh": "刷新",
|
||||||
|
"dismiss": "忽略"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -32,6 +32,11 @@ export const useConfigStore = defineStore('config', () => {
|
|||||||
provider: 'tavily',
|
provider: 'tavily',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
// The version user dismissed the update notification
|
||||||
|
const dismissUpdateVersion = useLocalStorage<string>(
|
||||||
|
'dismiss-update-version',
|
||||||
|
'',
|
||||||
|
)
|
||||||
|
|
||||||
const aiApiBase = computed(() => {
|
const aiApiBase = computed(() => {
|
||||||
return config.value.ai.apiBase || 'https://api.openai.com/v1'
|
return config.value.ai.apiBase || 'https://api.openai.com/v1'
|
||||||
@ -39,5 +44,10 @@ export const useConfigStore = defineStore('config', () => {
|
|||||||
|
|
||||||
const showConfigManager = ref(false)
|
const showConfigManager = ref(false)
|
||||||
|
|
||||||
return { config: skipHydrate(config), aiApiBase, showConfigManager }
|
return {
|
||||||
|
config: skipHydrate(config),
|
||||||
|
aiApiBase,
|
||||||
|
showConfigManager,
|
||||||
|
dismissUpdateVersion: skipHydrate(dismissUpdateVersion),
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user