- 将 StartLooking 函数重命名为 StartUpload 以更准确反映功能 - 修复构建脚本中的版本标记 ldflags 格式问题 - 更新应用标题格式,在版本号前添加冒号分隔符 - 优化上传进度循环逻辑,调整代码执行顺序 - 添加注释说明上传程序启动和文件处理功能 - 清理代码中的多余空行和变量声明
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user