mirror of
https://github.com/AynaLivePlayer/AynaLivePlayer.git
synced 2026-05-03 13:55:46 +08:00
update webinfo control panel
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"AynaLivePlayer/plugin/diange"
|
||||
"AynaLivePlayer/plugin/qiege"
|
||||
"AynaLivePlayer/plugin/textinfo"
|
||||
"AynaLivePlayer/plugin/webinfo"
|
||||
"AynaLivePlayer/plugin/wylogin"
|
||||
"fmt"
|
||||
"github.com/mitchellh/panicwrap"
|
||||
@@ -25,7 +26,7 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
var plugins = []controller.Plugin{diange.NewDiange(), qiege.NewQiege(), textinfo.NewTextInfo(),
|
||||
var plugins = []controller.Plugin{diange.NewDiange(), qiege.NewQiege(), textinfo.NewTextInfo(), webinfo.NewWebInfo(),
|
||||
wylogin.NewWYLogin()}
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -248,10 +248,6 @@
|
||||
"en": "User",
|
||||
"zh-CN": "普通用户"
|
||||
},
|
||||
"plugin.neteaselogin.logout": {
|
||||
"en": "Logout",
|
||||
"zh-CN": "登出"
|
||||
},
|
||||
"plugin.neteaselogin.current_user": {
|
||||
"en": "Current User:",
|
||||
"zh-CN": "当前用户:"
|
||||
@@ -264,6 +260,10 @@
|
||||
"en": "Netease User Login",
|
||||
"zh-CN": "网易云登录"
|
||||
},
|
||||
"plugin.neteaselogin.logout": {
|
||||
"en": "Logout",
|
||||
"zh-CN": "登出"
|
||||
},
|
||||
"plugin.neteaselogin.qr.finish": {
|
||||
"en": "Finish Scan",
|
||||
"zh-CN": "完成扫描后按我"
|
||||
@@ -328,6 +328,38 @@
|
||||
"en": "Web output configuration",
|
||||
"zh-CN": "web输出设置"
|
||||
},
|
||||
"plugin.webinfo.port": {
|
||||
"en": "Port",
|
||||
"zh-CN": "服务器端口"
|
||||
},
|
||||
"plugin.webinfo.server_control": {
|
||||
"en": "Control",
|
||||
"zh-CN": "操作"
|
||||
},
|
||||
"plugin.webinfo.server_control.restart": {
|
||||
"en": "Restart",
|
||||
"zh-CN": "重启"
|
||||
},
|
||||
"plugin.webinfo.server_control.start": {
|
||||
"en": "Start",
|
||||
"zh-CN": "启动"
|
||||
},
|
||||
"plugin.webinfo.server_control.stop": {
|
||||
"en": "Stop",
|
||||
"zh-CN": "停止"
|
||||
},
|
||||
"plugin.webinfo.server_status": {
|
||||
"en": "Server Status",
|
||||
"zh-CN": "服务器状态"
|
||||
},
|
||||
"plugin.webinfo.server_status.running": {
|
||||
"en": "Running",
|
||||
"zh-CN": "运行中"
|
||||
},
|
||||
"plugin.webinfo.server_status.stopped": {
|
||||
"en": "Stopped",
|
||||
"zh-CN": "已停止"
|
||||
},
|
||||
"plugin.webinfo.title": {
|
||||
"en": "Web Output",
|
||||
"zh-CN": "Web输出"
|
||||
|
||||
@@ -19,11 +19,13 @@ var upgrader = websocket.Upgrader{
|
||||
}
|
||||
|
||||
type WebInfoServer struct {
|
||||
Info OutInfo
|
||||
Server *http.Server
|
||||
Clients map[*Client]int
|
||||
Running bool
|
||||
lock sync.Mutex
|
||||
Info OutInfo
|
||||
Port int
|
||||
ServerMux *http.ServeMux
|
||||
Server *http.Server
|
||||
Clients map[*Client]int
|
||||
Running bool
|
||||
lock sync.Mutex
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
@@ -34,16 +36,15 @@ type Client struct {
|
||||
|
||||
func NewWebInfoServer(port int) *WebInfoServer {
|
||||
server := &WebInfoServer{
|
||||
Port: port,
|
||||
Clients: map[*Client]int{},
|
||||
}
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle("/", http.FileServer(http.Dir(config.GetAssetPath("webinfo"))))
|
||||
mux.HandleFunc("/ws/info", server.handleInfo)
|
||||
mux.HandleFunc("/api/info", server.getInfo)
|
||||
server.Server = &http.Server{
|
||||
Addr: fmt.Sprintf("localhost:%d", port),
|
||||
Handler: mux,
|
||||
}
|
||||
server.ServerMux = mux
|
||||
|
||||
return server
|
||||
}
|
||||
|
||||
@@ -128,12 +129,17 @@ func (s *WebInfoServer) removeClient(c *Client) {
|
||||
}
|
||||
|
||||
func (s *WebInfoServer) Start() {
|
||||
lg.Debug("WebInfoServer starting...")
|
||||
s.Running = true
|
||||
go func() {
|
||||
s.Server = &http.Server{
|
||||
Addr: fmt.Sprintf("localhost:%d", s.Port),
|
||||
Handler: s.ServerMux,
|
||||
}
|
||||
err := s.Server.ListenAndServe()
|
||||
s.Running = false
|
||||
if err == http.ErrServerClosed {
|
||||
lg.Info("server closed")
|
||||
lg.Info("WebInfoServer closed")
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
@@ -144,8 +150,9 @@ func (s *WebInfoServer) Start() {
|
||||
}
|
||||
|
||||
func (s *WebInfoServer) Stop() error {
|
||||
lg.Debug("WebInfoServer stopping...")
|
||||
s.lock.Lock()
|
||||
s.Clients = map[*Client]int{}
|
||||
s.lock.Unlock()
|
||||
return s.Server.Shutdown(context.Background())
|
||||
return s.Server.Shutdown(context.TODO())
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@ import (
|
||||
"AynaLivePlayer/logger"
|
||||
"AynaLivePlayer/player"
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"fyne.io/fyne/v2/data/binding"
|
||||
"fyne.io/fyne/v2/theme"
|
||||
"fyne.io/fyne/v2/widget"
|
||||
"github.com/aynakeya/go-mpv"
|
||||
)
|
||||
@@ -20,6 +23,7 @@ var lg = logger.Logger.WithField("Module", MODULE_PLGUIN_WEBINFO)
|
||||
type WebInfo struct {
|
||||
Port int
|
||||
server *WebInfoServer
|
||||
panel fyne.CanvasObject
|
||||
}
|
||||
|
||||
func NewWebInfo() *WebInfo {
|
||||
@@ -132,9 +136,79 @@ func (t *WebInfo) registerHandlers() {
|
||||
OutInfo{Lyric: t.server.Info.Lyric},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
func (w *WebInfo) getServerStatusText() string {
|
||||
if w.server.Running {
|
||||
return i18n.T("plugin.webinfo.server_status.running")
|
||||
} else {
|
||||
return i18n.T("plugin.webinfo.server_status.stopped")
|
||||
}
|
||||
}
|
||||
|
||||
func (w *WebInfo) CreatePanel() fyne.CanvasObject {
|
||||
return widget.NewLabel("No Setting")
|
||||
if w.panel != nil {
|
||||
return w.panel
|
||||
}
|
||||
statusText := widget.NewLabel("")
|
||||
serverStatus := container.NewHBox(
|
||||
widget.NewLabel(i18n.T("plugin.webinfo.server_status")),
|
||||
statusText,
|
||||
)
|
||||
statusText.SetText(w.getServerStatusText())
|
||||
serverPort := container.NewBorder(nil, nil,
|
||||
widget.NewLabel(i18n.T("plugin.webinfo.port")), nil,
|
||||
widget.NewEntryWithData(binding.IntToString(binding.BindInt(&w.Port))),
|
||||
)
|
||||
stopBtn := gui.NewAsyncButtonWithIcon(
|
||||
i18n.T("plugin.webinfo.server_control.stop"),
|
||||
theme.MediaStopIcon(),
|
||||
func() {
|
||||
if !w.server.Running {
|
||||
return
|
||||
}
|
||||
lg.Info("User try stop webinfo server")
|
||||
err := w.server.Stop()
|
||||
if err != nil {
|
||||
lg.Warnf("stop server have error: %s", err)
|
||||
return
|
||||
}
|
||||
statusText.SetText(w.getServerStatusText())
|
||||
},
|
||||
)
|
||||
startBtn := gui.NewAsyncButtonWithIcon(
|
||||
i18n.T("plugin.webinfo.server_control.start"),
|
||||
theme.MediaPlayIcon(),
|
||||
func() {
|
||||
if w.server.Running {
|
||||
return
|
||||
}
|
||||
lg.Infof("User try start webinfo server with port %d", w.Port)
|
||||
w.server.Port = w.Port
|
||||
w.server.Start()
|
||||
statusText.SetText(w.getServerStatusText())
|
||||
},
|
||||
)
|
||||
restartBtn := gui.NewAsyncButtonWithIcon(
|
||||
i18n.T("plugin.webinfo.server_control.restart"),
|
||||
theme.MediaReplayIcon(),
|
||||
func() {
|
||||
lg.Infof("User try restart webinfo server with port %d", w.Port)
|
||||
if w.server.Running {
|
||||
if err := w.server.Stop(); err != nil {
|
||||
lg.Warnf("stop server have error: %s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
w.server.Port = w.Port
|
||||
w.server.Start()
|
||||
statusText.SetText(w.getServerStatusText())
|
||||
},
|
||||
)
|
||||
ctrlBtns := container.NewHBox(
|
||||
widget.NewLabel(i18n.T("plugin.webinfo.server_control")),
|
||||
startBtn, stopBtn, restartBtn,
|
||||
)
|
||||
w.panel = container.NewVBox(serverStatus, serverPort, ctrlBtns)
|
||||
return w.panel
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user