refactor(app): 重构应用状态管理和配置常量定义
- 将全局变量 isRun 移动到 App 结构体内部作为实例字段 - 在 config.go 中定义配置键名为常量,提高代码可维护性 - 使用结构体实例字段替代全局变量管理上传状态 - 修改 StartLooking 函数中的上下文取消处理逻辑 - 移除上传程序退出日志的重复记录
This commit is contained in:
@@ -33,17 +33,23 @@ type Progress struct {
|
||||
}
|
||||
|
||||
func StartLooking(ctx context.Context, logChan *chan string, lookingPath string) {
|
||||
//推送上传进度
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
default:
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
var pg []Progress
|
||||
progress.Range(func(key, value any) bool {
|
||||
p := value.(Progress)
|
||||
pg = append(pg, p)
|
||||
return true
|
||||
})
|
||||
runtime.EventsEmit(ctx, "progress", pg)
|
||||
var pg []Progress
|
||||
progress.Range(func(key, value any) bool {
|
||||
p := value.(Progress)
|
||||
pg = append(pg, p)
|
||||
return true
|
||||
})
|
||||
runtime.EventsEmit(ctx, "progress", pg)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -52,7 +58,6 @@ func StartLooking(ctx context.Context, logChan *chan string, lookingPath string)
|
||||
select {
|
||||
case <-time.After(time.Minute):
|
||||
case <-ctx.Done():
|
||||
AddLog(logChan, "上传程序已退出")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user