mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
REST API keyboard.
This commit is contained in:
parent
db820806a4
commit
ac2fc100b4
@ -60,4 +60,9 @@ func (h *RoomHandler) Route(r chi.Router) {
|
||||
r.Post("/start", h.BoradcastStart)
|
||||
r.Post("/stop", h.BoradcastStop)
|
||||
})
|
||||
|
||||
r.With(auth.HostsOnly).Route("/keyboard", func(r chi.Router) {
|
||||
r.Post("/layout", h.KeyboardLayoutSet)
|
||||
r.Post("/modifiers", h.KeyboardModifiersSet)
|
||||
})
|
||||
}
|
||||
|
@ -1 +1,60 @@
|
||||
package room
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"demodesk/neko/internal/utils"
|
||||
)
|
||||
|
||||
type KeyboardLayoutData struct {
|
||||
Layout string `json:"layout"`
|
||||
}
|
||||
|
||||
type KeyboardModifiersData struct {
|
||||
NumLock *bool `json:"numlock"`
|
||||
CapsLock *bool `json:"capslock"`
|
||||
ScrollLock *bool `json:"scrollock"`
|
||||
}
|
||||
|
||||
func (h *RoomHandler) KeyboardLayoutSet(w http.ResponseWriter, r *http.Request) {
|
||||
data := &KeyboardLayoutData{}
|
||||
if !utils.HttpJsonRequest(w, r, data) {
|
||||
return
|
||||
}
|
||||
|
||||
h.desktop.SetKeyboardLayout(data.Layout)
|
||||
|
||||
utils.HttpSuccess(w)
|
||||
}
|
||||
|
||||
func (h *RoomHandler) KeyboardModifiersSet(w http.ResponseWriter, r *http.Request) {
|
||||
data := &KeyboardModifiersData{}
|
||||
if !utils.HttpJsonRequest(w, r, data) {
|
||||
return
|
||||
}
|
||||
|
||||
var NumLock = 0
|
||||
if data.NumLock == nil {
|
||||
NumLock = -1
|
||||
} else if *data.NumLock {
|
||||
NumLock = 1
|
||||
}
|
||||
|
||||
var CapsLock = 0
|
||||
if data.CapsLock == nil {
|
||||
CapsLock = -1
|
||||
} else if *data.CapsLock {
|
||||
CapsLock = 1
|
||||
}
|
||||
|
||||
var ScrollLock = 0
|
||||
if data.ScrollLock == nil {
|
||||
ScrollLock = -1
|
||||
} else if *data.ScrollLock {
|
||||
ScrollLock = 1
|
||||
}
|
||||
|
||||
h.desktop.SetKeyboardModifiers(NumLock, CapsLock, ScrollLock)
|
||||
|
||||
utils.HttpSuccess(w)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user