Skip to content

feat: Support for pasting images from clipboard#569

Open
Kruemmelspalter wants to merge 1 commit into
cinnyapp:mainfrom
Kruemmelspalter:feat-paste-images
Open

feat: Support for pasting images from clipboard#569
Kruemmelspalter wants to merge 1 commit into
cinnyapp:mainfrom
Kruemmelspalter:feat-paste-images

Conversation

@Kruemmelspalter

@Kruemmelspalter Kruemmelspalter commented Mar 31, 2026

Copy link
Copy Markdown

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 patches directory. 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 to beforeBuildCommand in 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 the if(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

@github-actions

github-actions Bot commented Mar 31, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@Kruemmelspalter

Kruemmelspalter commented Mar 31, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

ajbura added a commit to cinnyapp/cla that referenced this pull request Mar 31, 2026
@Kruemmelspalter Kruemmelspalter changed the title Support for pasting images from clipboard feat: Support for pasting images from clipboard Mar 31, 2026
@Kruemmelspalter

Copy link
Copy Markdown
Author

wrt build failure: does the windows builder not have git installed?

@kfiven

kfiven commented Apr 12, 2026

Copy link
Copy Markdown
Member

@speedy-lex

Copy link
Copy Markdown

Is the build on windows maybe failing because of ; to separate commands?

@CEbbinghaus CEbbinghaus left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just a few thoughts I had

Comment thread patches/clipboard.patch
+ const b64Image = await window.__TAURI__.core.invoke('paste_file');
+ if (b64Image)
+ onPaste([
+ new File([Uint8Array.fromBase64(b64Image)], 'image.png', { type: 'image/png' }),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src-tauri/tauri.conf.json Outdated
},
"build": {
"beforeBuildCommand": "cd cinny && npm run build",
"beforeBuildCommand": "bash -c \"cd cinny; git apply ../patches/*.patch; npm run build\"",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Not a huge fan of how we apply it here but I'm not sure how else we can make it work

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

yes, same
this currently breaks the windows builds
but I haven't found a better way so far

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

have you tried shx, I have recently added this for

"tauri": "shx cp config.json cinny/ && tauri",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment on lines +14 to +18
let image: RgbaImage = ImageBuffer::from_raw(
image_data.width as u32,
image_data.height as u32,
image_data.bytes.into_owned(),
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I have a strange suspicion this also won't support gifs... Can we confirm what image types this supports?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@Kruemmelspalter

Copy link
Copy Markdown
Author

@CEbbinghaus as far as I see, arboard only allows getting text or an image or a list of files (?) without any mime type info
I've looked for other clipboard libraries none that have support for all the platforms that arboard has (windows, mac, linux (x11 + wayland), iOS, android)
there is https://github.com/CrossCopy/tauri-plugin-clipboard though, which we could try

@CEbbinghaus

Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Image paste not working from clipboard

4 participants