mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-11 08:19:01 +08:00
fix: remove compareVersions utility and update version check logic in AboutSettings (#8640)
This commit is contained in:
parent
0f7091f3a8
commit
3a2a9d26eb
@ -10,7 +10,7 @@ import i18n from '@renderer/i18n'
|
|||||||
import { useAppDispatch } from '@renderer/store'
|
import { useAppDispatch } from '@renderer/store'
|
||||||
import { setUpdateState } from '@renderer/store/runtime'
|
import { setUpdateState } from '@renderer/store/runtime'
|
||||||
import { ThemeMode } from '@renderer/types'
|
import { ThemeMode } from '@renderer/types'
|
||||||
import { compareVersions, runAsyncFunction } from '@renderer/utils'
|
import { runAsyncFunction } from '@renderer/utils'
|
||||||
import { UpgradeChannel } from '@shared/config/constant'
|
import { UpgradeChannel } from '@shared/config/constant'
|
||||||
import { Avatar, Button, Progress, Radio, Row, Switch, Tag, Tooltip } from 'antd'
|
import { Avatar, Button, Progress, Radio, Row, Switch, Tag, Tooltip } from 'antd'
|
||||||
import { debounce } from 'lodash'
|
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 =
|
const currentChannelByVersion =
|
||||||
[
|
[
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { describe, expect, it } from 'vitest'
|
import { describe, expect, it } from 'vitest'
|
||||||
|
|
||||||
import { runAsyncFunction } from '../index'
|
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('Unclassified Utils', () => {
|
||||||
describe('runAsyncFunction', () => {
|
describe('runAsyncFunction', () => {
|
||||||
@ -110,32 +110,4 @@ describe('Unclassified Utils', () => {
|
|||||||
expect(hasPath('')).toBe(false)
|
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)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|||||||
@ -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 模态框参数
|
* @param {ModalFuncProps} params 模态框参数
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user