mirror of
https://github.com/m1k1o/neko.git
synced 2025-05-28 08:27:09 +02:00
xevent to update clipboard.
This commit is contained in:
parent
910f0af995
commit
a2ca3727fe
6 changed files with 46 additions and 42 deletions
|
@ -47,7 +47,6 @@ type WebSocketManagerCtx struct {
|
|||
desktop types.DesktopManager
|
||||
handler *handler.MessageHandlerCtx
|
||||
handlers []types.HandlerFunction
|
||||
shutdown chan bool
|
||||
}
|
||||
|
||||
func (ws *WebSocketManagerCtx) Start() {
|
||||
|
@ -118,51 +117,25 @@ func (ws *WebSocketManagerCtx) Start() {
|
|||
}, nil)
|
||||
})
|
||||
|
||||
go func() {
|
||||
ws.logger.Info().Msg("clipboard loop started")
|
||||
|
||||
defer func() {
|
||||
ws.logger.Info().Msg("clipboard loop stopped")
|
||||
}()
|
||||
|
||||
current := ws.desktop.ReadClipboard()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ws.shutdown:
|
||||
return
|
||||
default:
|
||||
session := ws.sessions.GetHost()
|
||||
if session == nil {
|
||||
break
|
||||
}
|
||||
|
||||
text := ws.desktop.ReadClipboard()
|
||||
if text == current {
|
||||
break
|
||||
}
|
||||
|
||||
current = text
|
||||
if !session.CanAccessClipboard() {
|
||||
break
|
||||
}
|
||||
|
||||
if err := session.Send(
|
||||
message.ClipboardData{
|
||||
Event: event.CLIPBOARD_UPDATED,
|
||||
Text: text,
|
||||
}); err != nil {
|
||||
ws.logger.Warn().Err(err).Msg("could not sync clipboard")
|
||||
}
|
||||
}
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
ws.desktop.OnClipboardUpdated(func() {
|
||||
session := ws.sessions.GetHost()
|
||||
if session == nil || !session.CanAccessClipboard() {
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
text := ws.desktop.ReadClipboard()
|
||||
err := session.Send(message.ClipboardData{
|
||||
Event: event.CLIPBOARD_UPDATED,
|
||||
Text: text,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
ws.logger.Warn().Err(err).Msg("could not sync clipboard")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (ws *WebSocketManagerCtx) Shutdown() error {
|
||||
ws.shutdown <- true
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue