refactor(middleware): 调整中间件执行顺序和代码格式化
All checks were successful
ci/woodpecker/tag/woodpecker Pipeline was successful

- 调整中间件执行顺序:将 TimeoutOver 移至 SoundStart 之前,确保超时检查在音频播放前生效
- 简化 BGM 停止逻辑:移除 select 语句中的多余花括号
- 修正导入顺序:将 sync 标准库导入置于第三方库之前

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-08 16:39:36 +08:00
parent cbccb07398
commit 1f527dce98
2 changed files with 8 additions and 11 deletions

View File

@@ -5,9 +5,10 @@ import (
"game-driver/leaf"
"game-driver/pkg/audio"
"game-driver/pkg/utils"
"sync"
"github.com/gopxl/beep/v2/speaker"
"go.uber.org/zap"
"sync"
)
// PlayBgm 播放背景音乐
@@ -44,15 +45,11 @@ func PlayBgm() leaf.HandlerFunc {
return
}
select {
case <-a:
{
<-a
speaker.Lock()
ctrl.Streamer = nil
speaker.Unlock()
return
}
}
}()
} else {
zap.S().Infoln("未解析到背景音乐")

View File

@@ -143,9 +143,9 @@ func Run() {
middleware.DeviceLock(device),
middleware.PauseWait(common.PassCtrl),
middleware.EmergencyStop(common.GlobalStopper),
middleware.TimeoutOver(config.C.MaxTimeout),
middleware.SoundStart(),
middleware.RelayMaster(r),
middleware.TimeoutOver(config.C.MaxTimeout),
middleware.TickerAction(),
middleware.PlayBgm(),
routes.PlayRouter(ctx, config.C.Location, config.C.Point),