Archived
2
0

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