mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
update clipboard WS.
This commit is contained in:
parent
2c210f3cf1
commit
e93d167be6
@ -22,7 +22,6 @@ const (
|
|||||||
CONTROL_LOCKED = "control/locked" // TODO: Remove.
|
CONTROL_LOCKED = "control/locked" // TODO: Remove.
|
||||||
CONTROL_REQUESTING = "control/requesting" // TODO: Remove.
|
CONTROL_REQUESTING = "control/requesting" // TODO: Remove.
|
||||||
CONTROL_GIVE = "control/give" // TODO: Remove.
|
CONTROL_GIVE = "control/give" // TODO: Remove.
|
||||||
CONTROL_CLIPBOARD = "control/clipboard" // TODO: Remove.
|
|
||||||
CONTROL_KEYBOARD = "control/keyboard" // TODO: Remove.
|
CONTROL_KEYBOARD = "control/keyboard" // TODO: Remove.
|
||||||
CONTROL_HOST = "control/host" // TODO: New.
|
CONTROL_HOST = "control/host" // TODO: New.
|
||||||
CONTROL_RELEASE = "control/release"
|
CONTROL_RELEASE = "control/release"
|
||||||
@ -42,8 +41,8 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CLIPBOARD_UPDATED = "clipboard/updated" // TODO: New.
|
CLIPBOARD_UPDATED = "clipboard/updated"
|
||||||
CLIPBOARD_SET = "clipboard/set" // TODO: New.
|
CLIPBOARD_SET = "clipboard/set"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -93,7 +93,6 @@ type ScreenSize struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Clipboard
|
// Clipboard
|
||||||
// TODO: New.
|
|
||||||
type ClipboardData struct {
|
type ClipboardData struct {
|
||||||
Event string `json:"event,omitempty"`
|
Event string `json:"event,omitempty"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
@ -153,12 +152,6 @@ type MemberDisconnected struct {
|
|||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Remove.
|
|
||||||
type Clipboard struct {
|
|
||||||
Event string `json:"event"`
|
|
||||||
Text string `json:"text"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Remove.
|
// TODO: Remove.
|
||||||
type Keyboard struct {
|
type Keyboard struct {
|
||||||
Event string `json:"event"`
|
Event string `json:"event"`
|
||||||
|
16
internal/websocket/handler/clipboard.go
Normal file
16
internal/websocket/handler/clipboard.go
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
package handler
|
||||||
|
|
||||||
|
import (
|
||||||
|
"demodesk/neko/internal/types"
|
||||||
|
"demodesk/neko/internal/types/message"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *MessageHandlerCtx) clipboardSet(session types.Session, payload *message.ClipboardData) error {
|
||||||
|
if !session.IsHost() {
|
||||||
|
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
h.desktop.WriteClipboard(payload.Text)
|
||||||
|
return nil
|
||||||
|
}
|
@ -82,16 +82,6 @@ func (h *MessageHandlerCtx) controlGive(session types.Session, payload *message.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *MessageHandlerCtx) controlClipboard(session types.Session, payload *message.Clipboard) error {
|
|
||||||
if !session.IsHost() {
|
|
||||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
h.desktop.WriteClipboard(payload.Text)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (h *MessageHandlerCtx) controlKeyboard(session types.Session, payload *message.Keyboard) error {
|
func (h *MessageHandlerCtx) controlKeyboard(session types.Session, payload *message.Keyboard) error {
|
||||||
if !session.IsHost() {
|
if !session.IsHost() {
|
||||||
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
h.logger.Debug().Str("id", session.ID()).Msg("is not the host")
|
||||||
|
@ -63,17 +63,19 @@ func (h *MessageHandlerCtx) Message(session types.Session, raw []byte) error {
|
|||||||
err = utils.Unmarshal(payload, raw, func() error {
|
err = utils.Unmarshal(payload, raw, func() error {
|
||||||
return h.controlGive(session, payload)
|
return h.controlGive(session, payload)
|
||||||
})
|
})
|
||||||
case event.CONTROL_CLIPBOARD:
|
|
||||||
payload := &message.Clipboard{}
|
|
||||||
err = utils.Unmarshal(payload, raw, func() error {
|
|
||||||
return h.controlClipboard(session, payload)
|
|
||||||
})
|
|
||||||
case event.CONTROL_KEYBOARD:
|
case event.CONTROL_KEYBOARD:
|
||||||
payload := &message.Keyboard{}
|
payload := &message.Keyboard{}
|
||||||
err = utils.Unmarshal(payload, raw, func() error {
|
err = utils.Unmarshal(payload, raw, func() error {
|
||||||
return h.controlKeyboard(session, payload)
|
return h.controlKeyboard(session, payload)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Clipboard Events
|
||||||
|
case event.CLIPBOARD_SET:
|
||||||
|
payload := &message.ClipboardData{}
|
||||||
|
err = utils.Unmarshal(payload, raw, func() error {
|
||||||
|
return h.clipboardSet(session, payload)
|
||||||
|
})
|
||||||
|
|
||||||
// Screen Events
|
// Screen Events
|
||||||
case event.SCREEN_RESOLUTION:
|
case event.SCREEN_RESOLUTION:
|
||||||
err = h.screenSize(session)
|
err = h.screenSize(session)
|
||||||
|
@ -98,8 +98,8 @@ func (ws *WebSocketManagerCtx) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := session.Send(
|
if err := session.Send(
|
||||||
message.Clipboard{
|
message.ClipboardData{
|
||||||
Event: event.CONTROL_CLIPBOARD,
|
Event: event.CLIPBOARD_UPDATED,
|
||||||
Text: text,
|
Text: text,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
ws.logger.Warn().Err(err).Msg("could not sync clipboard")
|
ws.logger.Warn().Err(err).Msg("could not sync clipboard")
|
||||||
|
Loading…
Reference in New Issue
Block a user