refactor(uploader): 重命名文件上传函数并优化代码结构
构建上传工具 / build-tool (push) Successful in 1m59s

- 将 StartLooking 函数重命名为 StartUpload 以更准确反映功能
- 修复构建脚本中的版本标记 ldflags 格式问题
- 更新应用标题格式,在版本号前添加冒号分隔符
- 优化上传进度循环逻辑,调整代码执行顺序
- 添加注释说明上传程序启动和文件处理功能
- 清理代码中的多余空行和变量声明
This commit is contained in:
2026-04-29 14:01:50 +08:00
parent a528d6a877
commit 3d2b3469cc
4 changed files with 13 additions and 10 deletions
+2 -2
View File
@@ -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
}
+9 -6
View File
@@ -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)
+1 -1
View File
@@ -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{