diff --git a/src/renderer/src/pages/settings/AboutSettings.tsx b/src/renderer/src/pages/settings/AboutSettings.tsx index 7ea35635a4..a97cfa7d74 100644 --- a/src/renderer/src/pages/settings/AboutSettings.tsx +++ b/src/renderer/src/pages/settings/AboutSettings.tsx @@ -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 = [ diff --git a/src/renderer/src/utils/__tests__/index.test.ts b/src/renderer/src/utils/__tests__/index.test.ts index 84c2b1d769..2ac46975e3 100644 --- a/src/renderer/src/utils/__tests__/index.test.ts +++ b/src/renderer/src/utils/__tests__/index.test.ts @@ -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) - }) - }) }) diff --git a/src/renderer/src/utils/index.ts b/src/renderer/src/utils/index.ts index 85275ad15d..c248027ccb 100644 --- a/src/renderer/src/utils/index.ts +++ b/src/renderer/src/utils/index.ts @@ -147,25 +147,6 @@ export function hasPath(url: string): boolean { } } -/** - * 比较两个版本号字符串。 - * @param {string} v1 第一个版本号 - * @param {string} v2 第二个版本号 - * @returns {number} 比较结果,1 表示 v1 大于 v2,-1 表示 v1 小于 v2,0 表示相等 - */ -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 模态框参数