2020-10-30 10:23:30 +13:00
|
|
|
package room
|
2020-11-19 09:53:06 +13:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2021-01-13 10:54:13 +13:00
|
|
|
"demodesk/neko/internal/types"
|
2021-02-15 02:40:17 +13:00
|
|
|
"demodesk/neko/internal/utils"
|
2020-11-19 09:53:06 +13:00
|
|
|
)
|
|
|
|
|
2021-01-16 04:53:03 +13:00
|
|
|
type KeyboardMapData struct {
|
2021-01-13 11:52:44 +13:00
|
|
|
Layout string `json:"layout"`
|
|
|
|
Variant string `json:"variant"`
|
2020-11-19 09:53:06 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
type KeyboardModifiersData struct {
|
2021-01-13 10:54:13 +13:00
|
|
|
NumLock *bool `json:"numlock"`
|
|
|
|
CapsLock *bool `json:"capslock"`
|
2020-11-19 09:53:06 +13:00
|
|
|
}
|
|
|
|
|
2021-01-16 04:53:03 +13:00
|
|
|
func (h *RoomHandler) keyboardMapSet(w http.ResponseWriter, r *http.Request) {
|
|
|
|
data := &KeyboardMapData{}
|
2020-11-19 09:53:06 +13:00
|
|
|
if !utils.HttpJsonRequest(w, r, data) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-16 04:53:03 +13:00
|
|
|
err := h.desktop.SetKeyboardMap(types.KeyboardMap{
|
2021-02-15 02:40:17 +13:00
|
|
|
Layout: data.Layout,
|
2021-01-16 04:53:03 +13:00
|
|
|
Variant: data.Variant,
|
|
|
|
})
|
|
|
|
|
2021-02-15 02:40:17 +13:00
|
|
|
if err != nil {
|
2021-04-25 07:37:43 +12:00
|
|
|
utils.HttpInternalServerError(w, "unable to change keyboard map")
|
2021-01-13 11:48:15 +13:00
|
|
|
return
|
|
|
|
}
|
2020-11-19 09:53:06 +13:00
|
|
|
|
|
|
|
utils.HttpSuccess(w)
|
|
|
|
}
|
|
|
|
|
2021-01-16 04:53:03 +13:00
|
|
|
func (h *RoomHandler) keyboardMapGet(w http.ResponseWriter, r *http.Request) {
|
|
|
|
data, err := h.desktop.GetKeyboardMap()
|
|
|
|
|
2021-02-15 02:40:17 +13:00
|
|
|
if err != nil {
|
2021-04-25 07:37:43 +12:00
|
|
|
utils.HttpInternalServerError(w, "unable to get keyboard map")
|
2021-01-16 04:53:03 +13:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
utils.HttpSuccess(w, KeyboardMapData{
|
2021-02-15 02:40:17 +13:00
|
|
|
Layout: data.Layout,
|
2021-01-16 04:53:03 +13:00
|
|
|
Variant: data.Variant,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-11-19 10:35:50 +13:00
|
|
|
func (h *RoomHandler) keyboardModifiersSet(w http.ResponseWriter, r *http.Request) {
|
2020-11-19 09:53:06 +13:00
|
|
|
data := &KeyboardModifiersData{}
|
|
|
|
if !utils.HttpJsonRequest(w, r, data) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-13 10:54:13 +13:00
|
|
|
h.desktop.SetKeyboardModifiers(types.KeyboardModifiers{
|
2021-02-15 02:40:17 +13:00
|
|
|
NumLock: data.NumLock,
|
2021-01-13 10:54:13 +13:00
|
|
|
CapsLock: data.CapsLock,
|
|
|
|
})
|
2020-11-19 09:53:06 +13:00
|
|
|
utils.HttpSuccess(w)
|
|
|
|
}
|
2021-01-13 11:35:46 +13:00
|
|
|
|
|
|
|
func (h *RoomHandler) keyboardModifiersGet(w http.ResponseWriter, r *http.Request) {
|
|
|
|
data := h.desktop.GetKeyboardModifiers()
|
|
|
|
|
|
|
|
utils.HttpSuccess(w, KeyboardModifiersData{
|
2021-02-15 02:40:17 +13:00
|
|
|
NumLock: data.NumLock,
|
2021-01-13 11:35:46 +13:00
|
|
|
CapsLock: data.CapsLock,
|
|
|
|
})
|
|
|
|
}
|