From 74194cd8ec3b55438fdc696321e72cd19a4eb1a6 Mon Sep 17 00:00:00 2001 From: edelaf01 Date: Sun, 2 Apr 2023 04:39:29 +0200 Subject: [PATCH] Added functionality It now detects any clipboard changes ,deletion being the main focus . Use case being ,for example, a password manager such as keepass and its auto-delete password from clipboard function. --- sync.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sync.go b/sync.go index 2986372..24ce75b 100644 --- a/sync.go +++ b/sync.go @@ -75,14 +75,17 @@ func (s *Syncer) Start(ctx context.Context, socket commSocket) { close(initChan) defer fmt.Println("clipboard listener stopped") - clipboardChanges := clipboard.Watch(s.ctx, clipboard.FmtText) - for newContent := range clipboardChanges { - s.mtx.Lock() + + // Keep checking for clipboard changes on the host machine + for { + newContent := clipboard.Read(clipboard.FmtText) if !bytes.Equal(newContent, s.clipboardContent) { + s.mtx.Lock() _ = socket.Write(1, newContent) s.clipboardContent = newContent + s.mtx.Unlock() } - s.mtx.Unlock() + time.Sleep(500 * time.Millisecond) } }() @@ -104,3 +107,4 @@ func (s *Syncer) Stop() { func (s *Syncer) ForceSync() { _ = s.socket.Write(1, s.clipboardContent) } +