mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-11-27 07:40:05 +08:00
fix(updater): gate cached updates on semver and confirm offers before installing
This commit is contained in:
@@ -15,7 +15,7 @@ import {
|
||||
} from '@/services/cmds'
|
||||
import { mutate } from '@/services/mutate'
|
||||
import { showNotice } from '@/services/notice-service'
|
||||
import { checkUpdateSafe as checkUpdate } from '@/services/update'
|
||||
import { checkForUpdate as checkUpdate } from '@/services/update'
|
||||
import { version } from '@root/package.json'
|
||||
|
||||
import { BackupViewer } from './mods/backup-viewer'
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { fetchCacheData, setCacheData, useQuery } from '@/services/query-client'
|
||||
import { checkUpdateSafe } from '@/services/update'
|
||||
import { checkForUpdate } from '@/services/update'
|
||||
|
||||
import { useVerge } from './use-verge'
|
||||
|
||||
@@ -26,7 +26,7 @@ export const useUpdate = (enabled: boolean = true) => {
|
||||
const shouldCheck = enabled && auto_check_update !== false
|
||||
|
||||
const fetchUpdate = async () => {
|
||||
const result = await checkUpdateSafe()
|
||||
const result = await checkForUpdate()
|
||||
updateLastCheckTime()
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -621,7 +621,6 @@ export type NetworkInterfaceView_Serialize = {
|
||||
}
|
||||
|
||||
export type NoticeStatus =
|
||||
| 'info'
|
||||
| 'import_sub_url::ok'
|
||||
| 'import_sub_url::error'
|
||||
| 'set_config::error'
|
||||
|
||||
@@ -35,9 +35,6 @@ const handlers: Record<
|
||||
NoticeStatus,
|
||||
(msg: string, navigate: NavigateFunction) => void
|
||||
> = {
|
||||
info: (msg) => {
|
||||
if (msg) showNotice.info(msg)
|
||||
},
|
||||
'import_sub_url::ok': (_msg, navigate) => {
|
||||
// 空 msg 传入,我们不希望导致 后端-前端-后端 死循环,这里只做提醒。
|
||||
// 未来细分事件通知时,可以考虑传入订阅 ID 或其他标识符
|
||||
|
||||
+4
-44
@@ -3,51 +3,11 @@ import {
|
||||
type CheckOptions,
|
||||
type Update,
|
||||
} from '@tauri-apps/plugin-updater'
|
||||
import { compareVersions as compareSemver } from 'compare-versions'
|
||||
|
||||
import { version as appVersion } from '@root/package.json'
|
||||
|
||||
const normalizeVersion = (input: string | null | undefined): string | null => {
|
||||
if (typeof input !== 'string') return null
|
||||
const trimmed = input.trim()
|
||||
if (!trimmed) return null
|
||||
return trimmed.replace(/^v/i, '')
|
||||
}
|
||||
|
||||
const compareVersions = (a: string | null, b: string | null): number | null => {
|
||||
if (!a || !b) return null
|
||||
try {
|
||||
return compareSemver(a, b)
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const localVersionNormalized = normalizeVersion(appVersion)
|
||||
|
||||
export const checkUpdateSafe = async (
|
||||
// The plugin's version comparator is overridden in src-tauri/src/lib.rs, so an update
|
||||
// returned by `check` is already installable and needs no extra filtering here.
|
||||
export const checkForUpdate = async (
|
||||
options?: CheckOptions,
|
||||
): Promise<Update | null> => {
|
||||
const result = await check(options ?? {})
|
||||
if (!result) return null
|
||||
|
||||
const remoteVersion = result.version
|
||||
const comparison = compareVersions(remoteVersion, localVersionNormalized)
|
||||
|
||||
const isBuildToStable =
|
||||
/^\d+\.\d+\.\d+\+[0-9A-Za-z.-]+$/.test(localVersionNormalized ?? '') &&
|
||||
remoteVersion === localVersionNormalized?.split('+')[0]
|
||||
|
||||
if (comparison !== null && comparison <= 0 && !isBuildToStable) {
|
||||
try {
|
||||
await result.close()
|
||||
} catch (err) {
|
||||
console.warn('[updater] failed to close stale update resource', err)
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
return result
|
||||
return check(options ?? {})
|
||||
}
|
||||
|
||||
export type { CheckOptions }
|
||||
|
||||
Reference in New Issue
Block a user