mirror of
https://github.com/m1k1o/neko.git
synced 2025-07-23 03:29:33 +02:00
clipboard sync and some minor fixes
This commit is contained in:
parent
e3a73aa264
commit
56a5dcf77f
22 changed files with 359 additions and 88 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
|
||||
"n.eko.moe/neko/internal/config"
|
||||
"n.eko.moe/neko/internal/hid/clipboard"
|
||||
"n.eko.moe/neko/internal/types"
|
||||
"n.eko.moe/neko/internal/types/event"
|
||||
"n.eko.moe/neko/internal/types/message"
|
||||
|
@ -51,20 +52,6 @@ type WebSocketHandler struct {
|
|||
}
|
||||
|
||||
func (ws *WebSocketHandler) Start() error {
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
ws.logger.Info().Msg("shutdown")
|
||||
}()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ws.shutdown:
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
ws.sessions.OnCreated(func(id string, session types.Session) {
|
||||
if err := ws.handler.SessionCreated(id, session); err != nil {
|
||||
ws.logger.Warn().Str("id", id).Err(err).Msg("session created with and error")
|
||||
|
@ -89,6 +76,40 @@ func (ws *WebSocketHandler) Start() error {
|
|||
}
|
||||
})
|
||||
|
||||
go func() {
|
||||
defer func() {
|
||||
ws.logger.Info().Msg("shutdown")
|
||||
}()
|
||||
|
||||
current := ""
|
||||
clip, err := clipboard.ReadAll()
|
||||
if err == nil && clip != current {
|
||||
current = clip
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ws.shutdown:
|
||||
return
|
||||
default:
|
||||
if ws.sessions.HasHost() {
|
||||
clip, err := clipboard.ReadAll()
|
||||
if err == nil && clip != current {
|
||||
session, ok := ws.sessions.GetHost()
|
||||
if ok {
|
||||
session.Send(message.Clipboard{
|
||||
Event: event.CONTROL_CLIPBOARD,
|
||||
Text: clip,
|
||||
})
|
||||
}
|
||||
current = clip
|
||||
}
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue