fix: remove compareVersions utility and update version check logic in AboutSettings (#8640)

This commit is contained in:
beyondkmp 2025-07-29 20:10:11 +08:00 committed by GitHub
parent 0f7091f3a8
commit 3a2a9d26eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 4 additions and 50 deletions

View File

@ -10,7 +10,7 @@ import i18n from '@renderer/i18n'
import { useAppDispatch } from '@renderer/store'
import { setUpdateState } from '@renderer/store/runtime'
import { ThemeMode } from '@renderer/types'
import { compareVersions, runAsyncFunction } from '@renderer/utils'
import { runAsyncFunction } from '@renderer/utils'
import { UpgradeChannel } from '@shared/config/constant'
import { Avatar, Button, Progress, Radio, Row, Switch, Tag, Tooltip } from 'antd'
import { debounce } from 'lodash'
@ -96,7 +96,8 @@ const AboutSettings: FC = () => {
})
}
const hasNewVersion = update?.info?.version && version ? compareVersions(update.info.version, version) > 0 : false
// don't support downgrade, so we only check if the version is different
const hasNewVersion = update?.info?.version && version ? update.info.version !== version : false
const currentChannelByVersion =
[

View File

@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest'
import { runAsyncFunction } from '../index'
import { compareVersions, hasPath, isFreeModel, isValidProxyUrl, removeQuotes, removeSpecialCharacters } from '../index'
import { hasPath, isFreeModel, isValidProxyUrl, removeQuotes, removeSpecialCharacters } from '../index'
describe('Unclassified Utils', () => {
describe('runAsyncFunction', () => {
@ -110,32 +110,4 @@ describe('Unclassified Utils', () => {
expect(hasPath('')).toBe(false)
})
})
describe('compareVersions', () => {
it('should return 1 if v1 > v2', () => {
expect(compareVersions('1.2.3', '1.2.2')).toBe(1)
expect(compareVersions('2.0.0', '1.9.9')).toBe(1)
expect(compareVersions('1.2.0', '1.1.9')).toBe(1)
expect(compareVersions('1.2.3', '1.2')).toBe(1)
})
it('should return -1 if v1 < v2', () => {
expect(compareVersions('1.2.2', '1.2.3')).toBe(-1)
expect(compareVersions('1.9.9', '2.0.0')).toBe(-1)
expect(compareVersions('1.1.9', '1.2.0')).toBe(-1)
expect(compareVersions('1.2', '1.2.3')).toBe(-1)
})
it('should return 0 if v1 == v2', () => {
expect(compareVersions('1.2.3', '1.2.3')).toBe(0)
expect(compareVersions('1.2', '1.2.0')).toBe(0)
expect(compareVersions('1.0.0', '1')).toBe(0)
})
it('should handle non-numeric and empty string', () => {
expect(compareVersions('', '')).toBe(0)
expect(compareVersions('a.b.c', '1.2.3')).toBe(-1)
expect(compareVersions('1.2.3', 'a.b.c')).toBe(1)
})
})
})

View File

@ -147,25 +147,6 @@ export function hasPath(url: string): boolean {
}
}
/**
*
* @param {string} v1
* @param {string} v2
* @returns {number} 1 v1 v2-1 v1 v20
*/
export const compareVersions = (v1: string, v2: string): number => {
const v1Parts = v1.split('.').map(Number)
const v2Parts = v2.split('.').map(Number)
for (let i = 0; i < Math.max(v1Parts.length, v2Parts.length); i++) {
const v1Part = v1Parts[i] || 0
const v2Part = v2Parts[i] || 0
if (v1Part > v2Part) return 1
if (v1Part < v2Part) return -1
}
return 0
}
/**
*
* @param {ModalFuncProps} params