mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
fix: correct version comparison logic
This commit is contained in:
parent
109bbef3cf
commit
e357700d60
@ -26,13 +26,31 @@ export async function checkUpdate(): Promise<IAppVersion | undefined> {
|
|||||||
)
|
)
|
||||||
const latest = yaml.parse(res.data, { merge: true }) as IAppVersion
|
const latest = yaml.parse(res.data, { merge: true }) as IAppVersion
|
||||||
const currentVersion = app.getVersion()
|
const currentVersion = app.getVersion()
|
||||||
if (latest.version !== currentVersion) {
|
if (compareVersions(latest.version, currentVersion) > 0) {
|
||||||
return latest
|
return latest
|
||||||
} else {
|
} else {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 1:新 -1:旧 0:相同
|
||||||
|
function compareVersions(a: string, b: string): number {
|
||||||
|
const parsePart = (part: string) => {
|
||||||
|
const numPart = part.split('-')[0]
|
||||||
|
const num = parseInt(numPart, 10)
|
||||||
|
return isNaN(num) ? 0 : num
|
||||||
|
}
|
||||||
|
const v1 = a.replace(/^v/, '').split('.').map(parsePart)
|
||||||
|
const v2 = b.replace(/^v/, '').split('.').map(parsePart)
|
||||||
|
for (let i = 0; i < Math.max(v1.length, v2.length); i++) {
|
||||||
|
const num1 = v1[i] || 0
|
||||||
|
const num2 = v2[i] || 0
|
||||||
|
if (num1 > num2) return 1
|
||||||
|
if (num1 < num2) return -1
|
||||||
|
}
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
export async function downloadAndInstallUpdate(version: string): Promise<void> {
|
export async function downloadAndInstallUpdate(version: string): Promise<void> {
|
||||||
const { 'mixed-port': mixedPort = 7890 } = await getControledMihomoConfig()
|
const { 'mixed-port': mixedPort = 7890 } = await getControledMihomoConfig()
|
||||||
const baseUrl = `https://github.com/mihomo-party-org/mihomo-party/releases/download/v${version}/`
|
const baseUrl = `https://github.com/mihomo-party-org/mihomo-party/releases/download/v${version}/`
|
||||||
@ -113,4 +131,4 @@ export async function downloadAndInstallUpdate(version: string): Promise<void> {
|
|||||||
rm(path.join(dataDir(), file))
|
rm(path.join(dataDir(), file))
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user