better Version and BuildTime handle

This commit is contained in:
wwqgtxx 2024-10-06 00:32:08 +08:00
parent f0f82fb9f9
commit 266c9da66d

View File

@ -2,6 +2,8 @@ package delegate
import ( import (
"errors" "errors"
"fmt"
"strings"
"syscall" "syscall"
"github.com/metacubex/mihomo/component/process" "github.com/metacubex/mihomo/component/process"
@ -19,7 +21,14 @@ var errBlocked = errors.New("blocked")
func Init(home, versionName, gitVersion string, platformVersion int) { func Init(home, versionName, gitVersion string, platformVersion int) {
log.Infoln("Init core, home: %s, versionName: %s, gitVersion: %s, platformVersion: %d", home, versionName, gitVersion, platformVersion) log.Infoln("Init core, home: %s, versionName: %s, gitVersion: %s, platformVersion: %d", home, versionName, gitVersion, platformVersion)
constant.SetHomeDir(home) constant.SetHomeDir(home)
constant.Version = gitVersion // gitVersion = ${CURRENT_BRANCH}_${COMMIT_HASH}_${COMPILE_TIME}
if versions := strings.Split(gitVersion, "_"); len(versions) == 3 {
constant.Version = fmt.Sprintf("%s-%s-CMFA-%s", strings.ToLower(versions[0]), versions[1], strings.ToLower(versionName))
constant.BuildTime = versions[2]
} else {
constant.Version = gitVersion
}
constant.Version = strings.ToLower(constant.Version)
app.ApplyVersionName(versionName) app.ApplyVersionName(versionName)
app.ApplyPlatformVersion(platformVersion) app.ApplyPlatformVersion(platformVersion)