From 3d2b3469cc65febc2f19d7287d169bdc74d6f593 Mon Sep 17 00:00:00 2001 From: YGXB_net Date: Wed, 29 Apr 2026 14:01:50 +0800 Subject: [PATCH] =?UTF-8?q?refactor(uploader):=20=E9=87=8D=E5=91=BD?= =?UTF-8?q?=E5=90=8D=E6=96=87=E4=BB=B6=E4=B8=8A=E4=BC=A0=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E5=B9=B6=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 StartLooking 函数重命名为 StartUpload 以更准确反映功能 - 修复构建脚本中的版本标记 ldflags 格式问题 - 更新应用标题格式,在版本号前添加冒号分隔符 - 优化上传进度循环逻辑,调整代码执行顺序 - 添加注释说明上传程序启动和文件处理功能 - 清理代码中的多余空行和变量声明 --- .gitea/workflows/build_tool.yaml | 2 +- app.go | 4 ++-- internal/uploader/uploader.go | 15 +++++++++------ main.go | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/.gitea/workflows/build_tool.yaml b/.gitea/workflows/build_tool.yaml index 1e2ecfa..aef60e3 100644 --- a/.gitea/workflows/build_tool.yaml +++ b/.gitea/workflows/build_tool.yaml @@ -56,7 +56,7 @@ jobs: build_date=$(TZ=Asia/Shanghai date +"%Y%m%d%H%M") wails build \ -platform windows/amd64 \ - -ldflags "-X 'main.version= $build_date - $git_hash'" \ + -ldflags "-X 'main.version=$build_date - $git_hash'" \ -o 上传工具.exe - name: 上传构建文件 diff --git a/app.go b/app.go index d85d695..7a433ed 100644 --- a/app.go +++ b/app.go @@ -48,7 +48,7 @@ func (a *App) startup(ctx context.Context) { if config.APPConfig.IsRunOnStart { time.Sleep(time.Second) a.uploaderCTX, a.uploaderCancel = context.WithCancel(a.ctx) - go uploader.StartLooking(a.uploaderCTX, &a.logChan, config.APPConfig.CheckDir) + go uploader.StartUpload(a.uploaderCTX, &a.logChan, config.APPConfig.CheckDir) a.isRun = true } } @@ -74,7 +74,7 @@ func (a *App) StartUpload() { return } a.uploaderCTX, a.uploaderCancel = context.WithCancel(a.ctx) - go uploader.StartLooking(a.uploaderCTX, &a.logChan, config.APPConfig.CheckDir) + go uploader.StartUpload(a.uploaderCTX, &a.logChan, config.APPConfig.CheckDir) a.isRun = true } diff --git a/internal/uploader/uploader.go b/internal/uploader/uploader.go index a05e224..4b0bdc1 100644 --- a/internal/uploader/uploader.go +++ b/internal/uploader/uploader.go @@ -34,7 +34,7 @@ type Progress struct { Percentage int `json:"percentage"` } -func StartLooking(ctx context.Context, logChan *chan string, lookingPath string) { +func StartUpload(ctx context.Context, logChan *chan string, lookingPath string) { AddLog(logChan, "===============================================") AddLog(logChan, `服务器: `+config.APPConfig.Url) AddLog(logChan, `Token: `+config.APPConfig.Token) @@ -48,6 +48,7 @@ func StartLooking(ctx context.Context, logChan *chan string, lookingPath string) AddLog(logChan, "创建连接池完成,开始运行程序") progress.Clear() + //推送上传进度 go func() { for { @@ -55,19 +56,19 @@ func StartLooking(ctx context.Context, logChan *chan string, lookingPath string) case <-ctx.Done(): return default: - time.Sleep(250 * time.Millisecond) - var pg []Progress - progress.Range(func(key, value any) bool { - p := value.(Progress) - pg = append(pg, p) + progress.Range(func(_, value any) bool { + pg = append(pg, value.(Progress)) return true }) wailsruntime.EventsEmit(ctx, "progress", pg) + + time.Sleep(250 * time.Millisecond) } } }() + //开启上传程序 for { uploadData(ctx, logChan, lookingPath) select { @@ -79,6 +80,7 @@ func StartLooking(ctx context.Context, logChan *chan string, lookingPath string) } func uploadData(ctx context.Context, logChan *chan string, lookingPath string) { + var path = "./" if lookingPath != "" { path = lookingPath @@ -210,6 +212,7 @@ func getTxtFiles(dir string) (txtFiles []string, err error) { return txtFiles, err } +// processFile 处理每个文件 func processFile(ctx context.Context, logChan *chan string, filePath string, fileLines int) { // 打开文件 file, err := os.Open(filePath) diff --git a/main.go b/main.go index f2e915a..47d9eae 100644 --- a/main.go +++ b/main.go @@ -22,7 +22,7 @@ func main() { // Create application with options err := wails.Run(&options.App{ - Title: "dypid-client - 版本" + version, + Title: "dypid-client - 版本:" + version, Width: 1024, Height: 768, AssetServer: &assetserver.Options{