Refactor version handling by renaming GetVersion to GetVersionFromAppConfig and updating references across main_cmd.go, main_ui.go, and other files. This change centralizes version retrieval from the application configuration, improving code clarity and maintainability.

This commit is contained in:
kony
2026-03-18 10:37:34 +08:00
parent 2a8b286fde
commit d02d9fda4b
9 changed files with 31 additions and 28 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ type FyneAppConfig struct {
} `toml:"Details"`
}
func GetVersion() string {
func GetVersionFromAppConfig() string {
var config FyneAppConfig
if _, err := toml.Decode(FyneAppToml, &config); err != nil {
log.Fatal(err)
+2 -2
View File
@@ -30,7 +30,7 @@ var (
Arg_local_forward_addrs string
)
func Help(ver string) {
func Help() {
v := flag.Bool("v", false, "查看版本信息")
Arg_local_config = flag.Bool("local_config", false, "优先加载本地配置")
@@ -65,7 +65,7 @@ func Help(ver string) {
flag.Parse()
if *v {
fmt.Printf("Version: %s\n", ver)
fmt.Printf("Version: %s\n", GetVersion())
fmt.Print(go2.BuildVersion())
os.Exit(0)
}
+13
View File
@@ -0,0 +1,13 @@
package config
var (
m_version string
)
func SetVersion(v string) {
m_version = v
}
func GetVersion() string {
return m_version
}
+3 -2
View File
@@ -46,7 +46,7 @@ func main2() {
}
}()
pro.SetVersion(GetVersion())
config.SetVersion(GetVersionFromAppConfig())
go2pool.Init()
@@ -79,7 +79,8 @@ func main2() {
}
func main() {
config.Help(GetVersion())
config.SetVersion(GetVersionFromAppConfig())
config.Help()
if config.Arg_stun_svr_ip != "" && config.Arg_stun_svr_port > 0 {
stun2.StartSvr(config.Arg_stun_svr_ip, config.Arg_stun_svr_port)
+3 -4
View File
@@ -5,7 +5,6 @@ package main
import (
"embed"
"goodlink/config"
"goodlink/pro"
_ "goodlink/pro"
"goodlink/theme"
"goodlink/ui2"
@@ -38,13 +37,13 @@ func main() {
config.DeleteLocalConfig()
config.Help(GetVersion())
config.SetVersion(GetVersionFromAppConfig())
pro.SetVersion(GetVersion())
config.Help()
myApp := app.New()
myApp.Settings().SetTheme(&theme.MyTheme{})
myWindow := myApp.NewWindow(M_APP_TITLE + " v" + GetVersion()) //myApp.Metadata().Version)
myWindow := myApp.NewWindow(M_APP_TITLE + " v" + config.GetVersion())
// 监听显示窗口请求
// Fyne的Show()方法会自动处理线程安全,可以直接在goroutine中调用
-9
View File
@@ -23,18 +23,9 @@ var (
m_redis_db *redis.Client
m_tun_key string
m_md5_tun_key string
m_version string
m_upnp_bind upnp.Upnp
)
func SetVersion(v string) {
m_version = v
}
func GetVersion() string {
return m_version
}
func Init(tun_key string) error {
var redis_addr string
var redis_pass string
+4 -4
View File
@@ -72,8 +72,8 @@ func handleState1_ProcessRemoteAddr(sessionID string, redisJson *RedisJsonType,
log.Printf("State 1: 收到Remote端地址: %v", redisJson.RemoteAddr)
// 版本兼容性检查
if redisJson.RemoteVersion != GetVersion() {
log.Printf("两端版本不兼容: Local: %s => Remote: %s", GetVersion(), redisJson.RemoteVersion)
if redisJson.RemoteVersion != config.GetVersion() {
log.Printf("两端版本不兼容: Local: %s => Remote: %s", config.GetVersion(), redisJson.RemoteVersion)
ui2.UpdateStartButtonStatue(ui2.TagStatusVersionMismatch)
RedisSessionDel(sessionID)
return errors.New("两端版本不兼容")
@@ -151,7 +151,7 @@ func GetLocalQuicConn(conn *net.UDPConn, addr *tun.AddrType, count int) (*tun.Tu
log.Printf("会话ID: %s", SessionID)
redisJson := RedisJsonType{
LocalVersion: GetVersion(),
LocalVersion: config.GetVersion(),
State: 0,
SessionID: SessionID,
ConnectCount: count,
@@ -188,7 +188,7 @@ func GetLocalQuicConn(conn *net.UDPConn, addr *tun.AddrType, count int) (*tun.Tu
case -1: // Remote端检测到版本不一致
ui2.UpdateStartButtonStatue(ui2.TagStatusVersionMismatch)
RedisSessionDel(SessionID)
return tun_active, tun_passive, nil, nil, nil, fmt.Errorf("和Remote端版本不一致: Local: %s => Remote: %s", GetVersion(), redisJson.RemoteVersion)
return tun_active, tun_passive, nil, nil, nil, fmt.Errorf("和Remote端版本不一致: Local: %s => Remote: %s", config.GetVersion(), redisJson.RemoteVersion)
case 1:
if err := handleState1_ProcessRemoteAddr(SessionID, &redisJson, conn, addr, conn_type, &tun_active, &tun_passive); err != nil {
+4 -4
View File
@@ -23,14 +23,14 @@ var (
func handleState1_SendRemoteAddr(sessionID string, redisJson *RedisJsonType, tun_active **tun.TunActive, tun_passive **tun.TunPassive, udp_conn **net.UDPConn, conn_type *int, tun_active_chain *chan *quic.Conn, tun_passive_chain *chan *quic.Conn) error {
log.Printf("会话 %s State 1: 发送Remote端地址", sessionID)
redisJson.RemoteVersion = GetVersion()
redisJson.RemoteVersion = config.GetVersion()
redisJson.State = 1
redisJson.SocketTimeOut = time.Duration(config.Arg_p2p_timeout) * time.Second
redisJson.RedisTimeOut = redisJson.SocketTimeOut * 3
// 版本兼容性检查
if redisJson.LocalVersion != GetVersion() {
log.Printf("会话 %s 两端版本不兼容: Local: %s => Remote: %s", sessionID, redisJson.LocalVersion, GetVersion())
if redisJson.LocalVersion != config.GetVersion() {
log.Printf("会话 %s 两端版本不兼容: Local: %s => Remote: %s", sessionID, redisJson.LocalVersion, config.GetVersion())
redisJson.State = -1 // 设置版本不一致状态,告知Local端
RedisSessionSet(sessionID, redisJson.SocketTimeOut*3, redisJson)
return errors.New("两端版本不兼容")
@@ -168,7 +168,7 @@ func processSession(redisJson *RedisJsonType) {
goto Release
}
redisJson.RemoteVersion = GetVersion()
redisJson.RemoteVersion = config.GetVersion()
redisJson.SocketTimeOut = time.Duration(config.Arg_p2p_timeout) * time.Second
redisJson.RedisTimeOut = redisJson.SocketTimeOut * 3
+1 -2
View File
@@ -275,8 +275,7 @@ func GetMainUI(myWindow *fyne.Window) *fyne.Container {
// 创建底部内容(启动按钮和页脚)
bottomContent := container.NewVBox(
startButtonContainer,
//NewFooter(pro.GetVersion()),
NewFooter("konyshe"),
NewFooter(config.GetVersion()),
)
// 使用 Border 布局,让日志区域自适应占用剩余空间