Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to have any exit condition. Previously, when we closed the clipboard, the watcher channel would be closed as well, therefore exiting the loop.

Copy link
Author

@edelaf01 edelaf01 Apr 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True , mb. Also i noticed that i want two things going at the same time and is making my brain work. If i wanted to notify the client that it may need to wait should i ask it to wait a set amount of time then ? Unless it gets updated then it just restarts the loop.

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)
}
}()

Expand All @@ -104,3 +107,4 @@ func (s *Syncer) Stop() {
func (s *Syncer) ForceSync() {
_ = s.socket.Write(1, s.clipboardContent)
}