golang-design / clipboard

📋 cross-platform clipboard package that supports accessing text and image in Go (macOS/Linux/Windows/Android/iOS)
https://golang.design/x/clipboard
MIT License
632 stars 68 forks source link

Doesn't work with some target application on Windows 10 #3

Closed DarkFighterLuke closed 3 years ago

DarkFighterLuke commented 3 years ago

Hi, congratulations for your library, it is very useful and especially it's written in pure Go. I have no problems at all while running on Linux, but when it comes to Windows problems magically appear (as always). Basically, I am putting an image received from the network into the clipboard, but on Windows I get a broken clipboard, which makes impossible to copy-paste anything until I stop the application. Using the clipboard history on Windows 10 I can partially see the image sent, but anyway all is gone. The image I am sending is PNG encoded at the source, then send to my application which takes the image bytes received in a multipart HTTP form and puts it into the clipboard.

Thanks for help.

UPDATE: I tried the demo tool gclip and it is able to save to a file the clipboard content, while ctrl+v (or gui equivalent) simply doesn't work as I said before. Once the file is saved, the clipboard begins to work again and I'm able to paste again.

changkun commented 3 years ago

Hi, thanks for reporting your experience on Windows. In fact, I am not an active Windows user, I added the Windows support while I was actively using Windows about a month ago and I don't have a window environment at the moment. As I remember from the dev experience, Window support for PNG data highly depends on the target application and requires either they provide valid BMP encoded header information in the clipboard or the target application handles the header well, sadly some of them does not and I tried my best to handle all the cases that I found. Since I worked one specific use of this package, which is midgard (a clipboard sharing service), works well on transferring image data between three systems (linux/windows/mac) and copy/pasting images between gclip and chrome (google slides as an example), then I published this package as a general abstraction.

I will try to see if I could find a windows environment tomorrow to further verify your case. Before that:

  1. Could you maybe provide your specific Windows 10 system version?
  2. What's your target application that is trying to copy image data from the clipboard?
  3. Is it possible for you to provide a minimum code that I can reproduce the problem easily?
DarkFighterLuke commented 3 years ago

First of all thanks for your very fast answer.

1. Could you maybe provide your specific Windows 10 system version?

2. What's your target application that is trying to copy image data from the clipboard?

3. Is it possible for you to provide a minimum code that I can reproduce the problem easily?
  1. My Windows version is Windows 10 Pro 20H2.
  2. The target application is Paint (at the moment).
  3. Sure, you can find the code here, in particular in server.go in the function handleIncomingImage.
changkun commented 3 years ago

Interesting, how did it work before, but nothing works now.

changkun commented 3 years ago

I got a fix and I will push it soon.

changkun commented 3 years ago

The bug is fixed in v0.4.5.