完善背光控制,优先使用 xset 控制。完成浏览器展示
This commit is contained in:
40
pkg/browser/browser.go
Normal file
40
pkg/browser/browser.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package browser
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/go-rod/rod"
|
||||
"github.com/go-rod/rod/lib/launcher"
|
||||
"github.com/go-rod/rod/lib/launcher/flags"
|
||||
"github.com/go-rod/rod/lib/proto"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// OpenApp 用APP模式打开网页
|
||||
func OpenApp(c context.Context, url string) {
|
||||
path, _ := launcher.LookPath()
|
||||
l := launcher.NewAppMode(url).
|
||||
Delete(flags.Env).
|
||||
Set("kiosk").
|
||||
Delete("disable-site-isolation-trials").
|
||||
Bin(path)
|
||||
p := l.MustLaunch()
|
||||
defer l.Cleanup()
|
||||
|
||||
b := rod.New().ControlURL(p).MustConnect()
|
||||
defer b.MustClose()
|
||||
|
||||
s := make(chan struct{})
|
||||
|
||||
wait := b.EachEvent(func(e *proto.TargetTargetDestroyed) {
|
||||
zap.S().Infoln("关闭待机网页")
|
||||
s <- struct{}{}
|
||||
})
|
||||
go wait()
|
||||
|
||||
select {
|
||||
case <-c.Done():
|
||||
b.MustClose()
|
||||
<-s
|
||||
case <-s:
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,24 @@
|
||||
package utils
|
||||
|
||||
import "os"
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// BlankOpen 打开屏幕
|
||||
func BlankOpen() {
|
||||
if found, err := exec.LookPath("xset"); err == nil {
|
||||
exec.Command(found, "dpms", "force", "on").Run()
|
||||
return
|
||||
}
|
||||
os.WriteFile("/sys/class/graphics/fb0/blank", []byte("0"), 0644)
|
||||
}
|
||||
|
||||
// BlankClose 关闭屏幕
|
||||
func BlankClose() {
|
||||
if found, err := exec.LookPath("xset"); err == nil {
|
||||
exec.Command(found, "dpms", "force", "off").Run()
|
||||
return
|
||||
}
|
||||
os.WriteFile("/sys/class/graphics/fb0/blank", []byte("1"), 0644)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user