feat(version): 优化版本比较和显示逻辑

- 修改版本比较逻辑,优先比较主版本号,然后是次版本号和修订号
- 增加对 beta版本的特殊处理,正式版比 beta 版更新
- 优化版本显示格式,移除不必要的 "v" 前缀
- 在主界面和日志中使用优化后的版本显示格式
This commit is contained in:
2025-08-04 00:12:36 +08:00
parent 8948d0fb18
commit 23b3691a13
3 changed files with 59 additions and 12 deletions

View File

@@ -563,7 +563,7 @@ func (app *Application) executeCheckingState() (UpdateState, error) {
default:
fmt.Printf("检查更新类别:%v\n", updateChannel)
}
fmt.Printf("当前版本:%v\n", currentVer)
fmt.Printf("当前版本:%s\n", app.formatVersionForDisplay(currentVer))
app.logger.Info("当前更新类别:" + updateChannel + ";当前版本:" + currentVer)
if err != nil {
app.logger.Error("检查更新失败: %v", err)
@@ -599,7 +599,7 @@ func (app *Application) executeCheckingState() (UpdateState, error) {
}
app.logger.Info("有可用更新: %s -> %s", currentVer, response.Data.VersionName)
fmt.Printf("发现新版本: %s -> %s\n", currentVer, response.Data.VersionName)
fmt.Printf("发现新版本: %s -> %s\n", app.formatVersionForDisplay(currentVer), response.Data.VersionName)
return StateUpdateAvailable, nil
}
@@ -813,6 +813,20 @@ func (app *Application) formatBytes(bytes int64) string {
return fmt.Sprintf("%.1f %cB", float64(bytes)/float64(div), "KMGTPE"[exp])
}
// formatVersionForDisplay 将版本格式转换为用户友好的显示格式
// 例如: "4.4.1.3" -> "4.4.1-beta3", "4.4.1.0" -> "4.4.1"
func (app *Application) formatVersionForDisplay(version string) string {
// 尝试解析版本
parsedVersion, err := appversion.ParseVersion(version)
if err != nil {
// 如果解析失败,返回原始版本
return version
}
// 使用 ToDisplayVersion 方法转换为显示格式
return parsedVersion.ToDisplayVersion()
}
// handleUserInteraction 处理 GUI 模式的用户交互
func (app *Application) handleUserInteraction(action string) {
switch action {