diff --git a/src/components/common/VersionChecker.tsx b/src/components/common/VersionChecker.tsx
index a5de4eb..83f0c2c 100644
--- a/src/components/common/VersionChecker.tsx
+++ b/src/components/common/VersionChecker.tsx
@@ -1,6 +1,6 @@
import React from 'react'
import { dialog, process } from '@tauri-apps/api'
-import { useVersion, useLatestVersion } from '@/components/common/useVersion'
+import { useVersion, useLatestVersion, CurrentVersion, LatestVersion } from '@/components/common/useVersion'
import Button from '@mui/material/Button'
import Typography from '@mui/material/Typography'
import DownloadIcon from '@mui/icons-material/Download'
@@ -53,8 +53,7 @@ export default function VersionChecker () {
if (latestVersion.isLoading) return 加载中...
if (latestVersion.isError) return 检查最新版本失败
- // TODO: semver
- const needUpdate = dayjs(version.data.date).isBefore(latestVersion.data.created_at)
+ const needUpdate = isNeedUpdate(version.data, latestVersion.data)
if (!needUpdate) return 已是最新版本
return (
@@ -67,3 +66,21 @@ export default function VersionChecker () {
)
}
+
+function isNeedUpdate (
+ version: CurrentVersion,
+ latestVersion: LatestVersion | null
+): boolean {
+ if (!latestVersion) return false
+
+ // TODO: Strictly compare semver
+ const current = version.version
+ const latest = latestVersion.tag_name
+ const currentSemver = current.split('.').map(v => parseInt(v))
+ const latestSemver = latest.split('.').map(v => parseInt(v))
+ for (let i = 0; i < 3; i++) {
+ if (currentSemver[i] < latestSemver[i]) return true
+ if (currentSemver[i] > latestSemver[i]) return false
+ }
+ return false
+}