mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
xevent on clipboard updated.
This commit is contained in:
parent
e9912ea87f
commit
9394b361bd
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user