refactor(utils): 禁用屏幕开关并优化 xset 查找逻辑
- 注释掉所有 BlankOpen/BlankClose 调用,启动不再关屏 - 将 xset 路径查找改为 init + sync.Once 缓存,避免重复执行 - 清理未使用的 utils 导入 Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -6,14 +6,15 @@ import (
|
|||||||
"game-driver/leaf"
|
"game-driver/leaf"
|
||||||
"game-driver/pkg/utils"
|
"game-driver/pkg/utils"
|
||||||
"game-driver/pkg/video"
|
"game-driver/pkg/video"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
func OnlyVideo(c *leaf.Context) {
|
func OnlyVideo(c *leaf.Context) {
|
||||||
payload := leaf.Value[*schema.PlayModal](c, middleware.PayloadJSONKey)
|
payload := leaf.Value[*schema.PlayModal](c, middleware.PayloadJSONKey)
|
||||||
|
|
||||||
utils.BlankOpen()
|
// utils.BlankOpen()
|
||||||
defer utils.BlankClose()
|
// defer utils.BlankClose()
|
||||||
|
|
||||||
if url, ok := payload.Game["video"]; ok {
|
if url, ok := payload.Game["video"]; ok {
|
||||||
path, local, err := utils.LinkVideo(url.(string))
|
path, local, err := utils.LinkVideo(url.(string))
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"game-driver/internal/schema"
|
"game-driver/internal/schema"
|
||||||
"game-driver/pkg/utils"
|
"game-driver/pkg/utils"
|
||||||
"game-driver/pkg/video"
|
"game-driver/pkg/video"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,8 +20,8 @@ func Video(item schema.WaitItemModel) func(c context.Context) error {
|
|||||||
zap.S().Infoln("播放待机视频")
|
zap.S().Infoln("播放待机视频")
|
||||||
defer zap.S().Infoln("结束待机视频")
|
defer zap.S().Infoln("结束待机视频")
|
||||||
|
|
||||||
utils.BlankOpen()
|
// utils.BlankOpen()
|
||||||
defer utils.BlankClose()
|
// defer utils.BlankClose()
|
||||||
|
|
||||||
err = video.Play(c, path, local)
|
err = video.Play(c, path, local)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"game-driver/internal/schema"
|
"game-driver/internal/schema"
|
||||||
"game-driver/pkg/browser"
|
"game-driver/pkg/browser"
|
||||||
"game-driver/pkg/utils"
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -13,8 +13,8 @@ func Web(item schema.WaitItemModel) func(c context.Context) error {
|
|||||||
zap.S().Infoln("打开待机网页")
|
zap.S().Infoln("打开待机网页")
|
||||||
|
|
||||||
// 控制背光
|
// 控制背光
|
||||||
utils.BlankOpen()
|
// utils.BlankOpen()
|
||||||
defer utils.BlankClose()
|
// defer utils.BlankClose()
|
||||||
|
|
||||||
browser.OpenApp(c, item.Data)
|
browser.OpenApp(c, item.Data)
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ func Run() {
|
|||||||
zap.S().Infoln("当前IP: ", addrs)
|
zap.S().Infoln("当前IP: ", addrs)
|
||||||
|
|
||||||
// 启动时关闭屏幕
|
// 启动时关闭屏幕
|
||||||
utils.BlankClose()
|
// utils.BlankClose()
|
||||||
|
|
||||||
topicPrefix := fmt.Sprintf("server/%s/%v/", config.C.Location, config.C.Point)
|
topicPrefix := fmt.Sprintf("server/%s/%v/", config.C.Location, config.C.Point)
|
||||||
publishTopic := fmt.Sprintf("device/%s/%v/status", config.C.Location, config.C.Point)
|
publishTopic := fmt.Sprintf("device/%s/%v/status", config.C.Location, config.C.Point)
|
||||||
|
|||||||
@@ -3,12 +3,26 @@ package utils
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
xsetBin string
|
||||||
|
once sync.Once
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
once.Do(func() {
|
||||||
|
if found, err := exec.LookPath("xset"); err == nil {
|
||||||
|
xsetBin = found
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// BlankOpen 打开屏幕
|
// BlankOpen 打开屏幕
|
||||||
func BlankOpen() {
|
func BlankOpen() {
|
||||||
if found, err := exec.LookPath("xset"); err == nil {
|
if xsetBin != "" {
|
||||||
exec.Command(found, "dpms", "force", "on").Run()
|
exec.Command(xsetBin, "dpms", "force", "on").Run()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
os.WriteFile("/sys/class/graphics/fb0/blank", []byte("0"), 0644)
|
os.WriteFile("/sys/class/graphics/fb0/blank", []byte("0"), 0644)
|
||||||
@@ -16,8 +30,8 @@ func BlankOpen() {
|
|||||||
|
|
||||||
// BlankClose 关闭屏幕
|
// BlankClose 关闭屏幕
|
||||||
func BlankClose() {
|
func BlankClose() {
|
||||||
if found, err := exec.LookPath("xset"); err == nil {
|
if xsetBin != "" {
|
||||||
exec.Command(found, "dpms", "force", "off").Run()
|
exec.Command(xsetBin, "dpms", "force", "off").Run()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
os.WriteFile("/sys/class/graphics/fb0/blank", []byte("1"), 0644)
|
os.WriteFile("/sys/class/graphics/fb0/blank", []byte("1"), 0644)
|
||||||
|
|||||||
Reference in New Issue
Block a user