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

View File

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