xevent on clipboard updated.

This commit is contained in:
Miroslav Šedivý 2022-09-16 00:01:15 +02:00
parent e9912ea87f
commit 9394b361bd

View File

@ -175,47 +175,19 @@ func (ws *WebSocketHandler) Start() {
} }
}) })
ws.wg.Add(1) ws.desktop.OnClipboardUpdated(func() {
go func() {
defer func() {
ws.logger.Info().Msg("shutdown")
ws.wg.Done()
}()
current := ws.desktop.ReadClipboard()
for {
select {
case <-ws.shutdown:
return
default:
time.Sleep(100 * time.Millisecond)
if !ws.sessions.HasHost() {
continue
}
text := ws.desktop.ReadClipboard()
if text == current {
continue
}
session, ok := ws.sessions.GetHost() session, ok := ws.sessions.GetHost()
if ok { if !ok {
return
}
err := session.Send(message.Clipboard{ err := session.Send(message.Clipboard{
Event: event.CONTROL_CLIPBOARD, Event: event.CONTROL_CLIPBOARD,
Text: text, Text: ws.desktop.ReadClipboard(),
}) })
if err != nil { ws.logger.Err(err).Msg("sync clipboard")
ws.logger.Err(err).Msg("unable to synchronize clipboard") })
}
}
current = text
}
}
}()
} }
func (ws *WebSocketHandler) Shutdown() error { func (ws *WebSocketHandler) Shutdown() error {