版本号单一来源,新增带版本号的 Windows exe 构建脚本

This commit is contained in:
yml2213
2026-10-14 21:34:08 +08:00
parent cff831ae47
commit 4208f1d82f
8 changed files with 88 additions and 4 deletions
+9
View File
@@ -26,6 +26,15 @@ wails build -debug -nopackage
GUI 二进制输出到 `build/bin/huya-gui`。开发时可以使用 `wails dev` 启动 Wails + React + Ant Design 界面。
Windows exe(文件名带版本号):
```bash
./scripts/build-windows.sh # 默认 windows/amd64
./scripts/build-windows.sh arm64 # 如需 windows/arm64
```
产物为 `build/bin/huya-gui-v<版本>.exe`(PE32+ GUI)。版本号的单一来源是 `internal/version/version.go`:脚本从这里读取版本号,既拼进 exe 文件名,也通过 `-ldflags "-X huya-go/internal/version.Version=..."` 编译进程序,界面左下角的版本标签来自同一个值。发布新版本时改这一处,并同步 `wails.json` 的 `info.productVersion`(只影响 exe 文件属性)。在 macOS 上交叉编译不会生成 NSIS 安装包(`-nopackage`),只产出 exe。
## Cookie
推荐把账号 Cookie 放到本地文件,一行一个账号:
+14 -3
View File
@@ -43,6 +43,7 @@ import {
GetLogs,
GetLogStats,
GetRecords,
GetVersion,
IsRunning,
ListPrizes,
OpenLogDir,
@@ -572,6 +573,7 @@ export default function Dashboard() {
const [logFilter, setLogFilter] = useState('all')
const [debugLog, setDebugLog] = useState(false)
const [instanceInfo, setInstanceInfo] = useState<InstanceInfo | null>(null)
const [appVersion, setAppVersion] = useState('')
const applyCookieEntries = async (entries: CookieEntry[], persist = true, refreshLatest = false) => {
const normalizedEntries = entries
@@ -616,13 +618,22 @@ export default function Dashboard() {
useEffect(() => {
let mounted = true
Promise.all([DefaultConfig(), GetLogs(0), IsRunning(), GetLogFilePath(), GetInstanceInfo(), GetLogStats()])
.then(([defaults, logItems, isRunning, savedLogPath, info, stats]) => {
Promise.all([
DefaultConfig(),
GetLogs(0),
IsRunning(),
GetLogFilePath(),
GetInstanceInfo(),
GetLogStats(),
GetVersion(),
])
.then(([defaults, logItems, isRunning, savedLogPath, info, stats, version]) => {
if (!mounted) return
const instance = info as InstanceInfo | null
// 本地存储必须按实例分片后再读取,否则多开时两个实例会共用同一份账号与配置。
applyStorageScope(instance?.id || '')
setInstanceInfo(instance)
setAppVersion(String(version || ''))
setLogStats((stats || null) as LogStats | null)
setDebugLog(String((stats as LogStats | null)?.level || '') === 'debug')
@@ -1437,7 +1448,7 @@ export default function Dashboard() {
<Typography.Title level={4}>虎牙抢购</Typography.Title>
<Typography.Text type="secondary">实时库存 · 多账号 · 定时触发</Typography.Text>
</div>
<Tag>v0.2.0</Tag>
<Tag>{appVersion || '…'}</Tag>
</div>
<Button
+2
View File
@@ -17,6 +17,8 @@ export function GetLogs(arg1:number):Promise<Array<logger.Entry>>;
export function GetRecords(arg1:gui.Config):Promise<Array<gui.RecordResult>>;
export function GetVersion():Promise<string>;
export function IsRunning():Promise<boolean>;
export function ListPrizes(arg1:gui.Config):Promise<gui.PrizeListResult>;
+4
View File
@@ -30,6 +30,10 @@ export function GetRecords(arg1) {
return window['go']['gui']['App']['GetRecords'](arg1);
}
export function GetVersion() {
return window['go']['gui']['App']['GetVersion']();
}
export function IsRunning() {
return window['go']['gui']['App']['IsRunning']();
}
+6
View File
@@ -15,6 +15,7 @@ import (
"huya-go/internal/instance"
"huya-go/internal/logger"
"huya-go/internal/sniper"
"huya-go/internal/version"
)
const (
@@ -246,6 +247,11 @@ func (a *App) GetInstanceInfo() InstanceInfo {
return info
}
// GetVersion 返回应用版本号(与 exe 文件名、编译期版本号同源)。
func (a *App) GetVersion() string {
return version.Display()
}
// OpenLogDir 用系统文件管理器打开日志目录。
func (a *App) OpenLogDir() error {
dir := logger.Dir()
+14
View File
@@ -0,0 +1,14 @@
// Package version 保存应用版本号,作为构建脚本、exe 文件名与界面显示的单一来源。
package version
// Version 是应用版本号。
//
// 构建时可用 ldflags 覆盖(构建脚本就是这么做的):
//
// go build -ldflags "-X huya-go/internal/version.Version=0.2.0"
var Version = "0.2.0"
// Display 返回带 v 前缀的展示版本号,例如 v0.2.0。
func Display() string {
return "v" + Version
}
+31
View File
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# 构建带版本号的 Windows exe。
#
# 用法:./scripts/build-windows.sh [amd64|arm64]
# 产物:build/bin/huya-gui-v<版本>.exe
#
# 版本号从 internal/version/version.go 读取,保证 exe 文件名、编译进去的版本号
# 与界面显示三者一致,不需要在多个地方手改。
set -euo pipefail
cd "$(dirname "$0")/.."
ARCH="${1:-amd64}"
VERSION="$(sed -n 's/^var Version = "\(.*\)"$/\1/p' internal/version/version.go)"
if [ -z "${VERSION}" ]; then
echo "无法从 internal/version/version.go 读取版本号" >&2
exit 1
fi
OUT="huya-gui-v${VERSION}.exe"
echo "构建 windows/${ARCH} -> build/bin/${OUT} (版本 v${VERSION})"
# -nopackage:交叉编译时不生成 NSIS 安装包,只产出 exe。
wails build \
-platform "windows/${ARCH}" \
-clean \
-nopackage \
-o "${OUT}" \
-ldflags "-X huya-go/internal/version.Version=${VERSION}"
echo "完成: build/bin/${OUT}"
+8 -1
View File
@@ -5,5 +5,12 @@
"frontend:install": "npm install",
"frontend:build": "npm run build",
"frontend:dev:watcher": "npm run dev",
"frontend:dev:serverUrl": "auto"
"frontend:dev:serverUrl": "auto",
"info": {
"companyName": "huya-go",
"productName": "虎牙抢购助手",
"productVersion": "0.2.0",
"copyright": "",
"comments": "虎牙活动积分兑换/抢购工具"
}
}