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() { session, ok := ws.sessions.GetHost()
defer func() { if !ok {
ws.logger.Info().Msg("shutdown") return
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()
if ok {
err := session.Send(message.Clipboard{
Event: event.CONTROL_CLIPBOARD,
Text: text,
})
if err != nil {
ws.logger.Err(err).Msg("unable to synchronize clipboard")
}
}
current = text
}
} }
}()
err := session.Send(message.Clipboard{
Event: event.CONTROL_CLIPBOARD,
Text: ws.desktop.ReadClipboard(),
})
ws.logger.Err(err).Msg("sync clipboard")
})
} }
func (ws *WebSocketHandler) Shutdown() error { func (ws *WebSocketHandler) Shutdown() error {