feat: Support for pasting images from clipboard#569
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
|
wrt build failure: does the windows builder not have git installed? |
|
Is the build on windows maybe failing because of ; to separate commands? |
6c584a9 to
85adb4b
Compare
| + const b64Image = await window.__TAURI__.core.invoke('paste_file'); | ||
| + if (b64Image) | ||
| + onPaste([ | ||
| + new File([Uint8Array.fromBase64(b64Image)], 'image.png', { type: 'image/png' }), |
There was a problem hiding this comment.
I would like to see magic byte detection to at least try and guess as to the image format. Especially important for animated images like gif.
| }, | ||
| "build": { | ||
| "beforeBuildCommand": "cd cinny && npm run build", | ||
| "beforeBuildCommand": "bash -c \"cd cinny; git apply ../patches/*.patch; npm run build\"", |
There was a problem hiding this comment.
Not a huge fan of how we apply it here but I'm not sure how else we can make it work
There was a problem hiding this comment.
yes, same
this currently breaks the windows builds
but I haven't found a better way so far
There was a problem hiding this comment.
have you tried shx, I have recently added this for
Line 10 in 9d12943
There was a problem hiding this comment.
or alternatively we can also try to apply patch separately of build command. Manually during local builds and adding a step in github actions for test/prod builds.
| let image: RgbaImage = ImageBuffer::from_raw( | ||
| image_data.width as u32, | ||
| image_data.height as u32, | ||
| image_data.bytes.into_owned(), | ||
| ) |
There was a problem hiding this comment.
I have a strange suspicion this also won't support gifs... Can we confirm what image types this supports?
There was a problem hiding this comment.
yes, this will convert any image to a png so gifs would probably just show the first frame
we could just pass the file straight through, which would make more sense because one would be able to paste any file and not just images
| image | ||
| .write_to( | ||
| &mut std::io::Cursor::new(&mut buffer), | ||
| image::ImageOutputFormat::Png, |
There was a problem hiding this comment.
as per above, I believe the image we recieve from the clipboard can also have a filename attached to it, so we may want to not only preserve that as part of the data we send, but also use it to determine file type.
074dae1 to
6cc265f
Compare
6cc265f to
f3a3887
Compare
|
@CEbbinghaus as far as I see, |
|
I had a look and it looks like not even tauri-plugin-clipboard handles animated gifs or more esoteric image encodings. So I suspect we will have to settle for plain png for now. I think we should still read the mime type out of the library to properly encode the image when sending. But other than that we won't need to change that much. I would however still look to move tauri-plugin-clipboard specifically because cinny uses tauri and thus fits the usecase better |
This builds heavily on @tobias-kuendig's work in #167 and cinnyapp/cinny#1238.
As said in cinnyapp/cinny#1238 (comment), they do not want any tauri specific code in cinnyapp/cinny.
As tauri doesn't support image pasting (reliably at least) and doesn't support sending custom paste events either, image pasting support needs source code changes. This PR implements this using patches in a
patchesdirectory. This is kind of scuffed but I couldn't come up with a different solution. I've added instructions to apply the patches to the README and added the command tobeforeBuildCommandin tauri.conf.json so as not to break existing build mechanisms. Applying the patches when already applied will print errors, which can be ignored. If any more patches were to be added, it would be good if they didn't break cinny without tauri (see for example theif(window.__TAURI__)check)I have no idea if this patches directory is a sensible solution that fits into the build workflow of this project, but I just couldn't find a different solution. Maybe it would make more sense to move the patches directory into /src-tauri but idk about that either.
I've tested this only on linux/wayland so far, but it should work on all other systems too.
closes #69