refactor(utils): 禁用屏幕开关并优化 xset 查找逻辑
- 注释掉所有 BlankOpen/BlankClose 调用,启动不再关屏 - 将 xset 路径查找改为 init + sync.Once 缓存,避免重复执行 - 清理未使用的 utils 导入 Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -3,12 +3,26 @@ package utils
|
||||
import (
|
||||
"os"
|
||||
"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 打开屏幕
|
||||
func BlankOpen() {
|
||||
if found, err := exec.LookPath("xset"); err == nil {
|
||||
exec.Command(found, "dpms", "force", "on").Run()
|
||||
if xsetBin != "" {
|
||||
exec.Command(xsetBin, "dpms", "force", "on").Run()
|
||||
return
|
||||
}
|
||||
os.WriteFile("/sys/class/graphics/fb0/blank", []byte("0"), 0644)
|
||||
@@ -16,8 +30,8 @@ func BlankOpen() {
|
||||
|
||||
// BlankClose 关闭屏幕
|
||||
func BlankClose() {
|
||||
if found, err := exec.LookPath("xset"); err == nil {
|
||||
exec.Command(found, "dpms", "force", "off").Run()
|
||||
if xsetBin != "" {
|
||||
exec.Command(xsetBin, "dpms", "force", "off").Run()
|
||||
return
|
||||
}
|
||||
os.WriteFile("/sys/class/graphics/fb0/blank", []byte("1"), 0644)
|
||||
|
||||
Reference in New Issue
Block a user