Merge branch 'main' into clean_beep

# Conflicts:
#	internal/routes/wait.go
This commit is contained in:
2025-07-09 11:58:14 +08:00
63 changed files with 2313 additions and 276 deletions

View File

@@ -0,0 +1,18 @@
package middleware
import (
"game-driver/config"
"game-driver/leaf"
"go.uber.org/zap"
)
// Cache 缓存中间件
func Cache(cache config.Cache) leaf.HandlerFunc {
return func(c *leaf.Context) {
err := cache.Set(c.Publish)
if err != nil {
zap.S().Errorln("缓存数据失败: ", err)
}
c.Next()
}
}

View File

@@ -0,0 +1,15 @@
package middleware
import (
"game-driver/internal/common"
"game-driver/leaf"
)
func PauseWait(ctrl *common.CtrlWait) leaf.HandlerFunc {
return func(c *leaf.Context) {
ctrl.Pause()
defer ctrl.Resume()
c.Next()
}
}

View File

@@ -14,8 +14,10 @@ func SoundStart() leaf.HandlerFunc {
defer func() {
switch leaf.Value[leaf.EndType](c, leaf.EndKey) {
case leaf.EndTimer:
case leaf.End:
tts.DefaultTTS.Sound(pm.TTS.End)
case leaf.EndTimeout:
tts.DefaultTTS.Sound(pm.TTS.Timeout)
case leaf.EndStop:
tts.DefaultTTS.Sound(pm.TTS.Stop)
}

View File

@@ -4,6 +4,7 @@ import (
"game-driver/internal/common"
"game-driver/leaf"
"go.uber.org/zap"
"sync"
)
// EmergencyStop 紧急停止中间件
@@ -12,14 +13,21 @@ func EmergencyStop(stopper common.Stopper) leaf.HandlerFunc {
cancel := leaf.WithCancel(c)
defer stopper.Reset()
zap.S().Infoln("监听停止信号")
defer zap.S().Infoln("结束停止信号监听")
// 等待组
var wait sync.WaitGroup
defer wait.Wait()
// 结束信号通道
a := make(chan struct{})
// 发送结束信号
defer close(a)
zap.S().Infoln("监听停止信号")
wait.Add(1)
go func() {
defer zap.S().Infoln("结束停止信号监听")
defer wait.Done()
select {
case <-a:

View File

@@ -9,6 +9,7 @@ import (
"time"
)
// TickerAction 定时器动作,用于在指定时间点执行打印和语音播报
func TickerAction() leaf.HandlerFunc {
return func(c *leaf.Context) {
pm := leaf.Value[*schema.PlayModal](c, PayloadJSONKey)

View File

@@ -8,7 +8,7 @@ import (
"time"
)
// TimeoutOver 定时器中间件,用于定时触发屏幕打印和语音播报。 t 是语音播报实例
// TimeoutOver 超时停止
func TimeoutOver(maxTimeout int) leaf.HandlerFunc {
return func(c *leaf.Context) {
pm := leaf.Value[*schema.PlayModal](c, PayloadJSONKey)
@@ -46,7 +46,7 @@ func TimeoutOver(maxTimeout int) leaf.HandlerFunc {
{
zap.S().Infoln("超时 Timer 触发")
cancel()
leaf.WithValue[leaf.EndType](c, leaf.EndKey, leaf.EndTimer)
leaf.WithValue[leaf.EndType](c, leaf.EndKey, leaf.EndTimeout)
}
}
}()

View File

@@ -12,7 +12,7 @@ func Unique(stopper common.Stopper) leaf.HandlerFunc {
var lock sync.Mutex
return func(c *leaf.Context) {
if !lock.TryLock() {
zap.S().Infoln("尝试加锁失败,执行停止任务")
zap.S().Infoln("停止之前的任务,再尝试加锁")
stopper.Stop()
lock.Lock()
}