CrossCopy / tauri-plugin-clipboard

A Tauri clipboard plugin with text, files, html, RTF, and image support. Clipboard content update monitoring is also supported.
https://crosscopy.github.io/tauri-plugin-clipboard/
MIT License
122 stars 6 forks source link

Some problems with copying images #31

Closed ayangweb closed 1 month ago

ayangweb commented 1 month ago

Hey 👋, I searched for a random image from my browser and copied the image, but it triggered the onHTMLUpdate event at the same time! Can this be optimized? It should only trigger the onImageUpdate event!

image
HuakunShen commented 1 month ago

This is the same as your other issue https://github.com/CrossCopy/tauri-plugin-clipboard/issues/32

Copying image from browser indeed triggers both html and image update.

I will add an option argument. For now you can implement your own listen function.

ayangweb commented 1 month ago

This is the same as your other issue #32

Copying image from browser indeed triggers both html and image update.

I will add an option argument. For now you can implement your own listen function.

Okay, thanks.

HuakunShen commented 1 month ago

In https://github.com/CrossCopy/tauri-plugin-clipboard/issues/32 the HTML + text event issue is addressed with a breakOnType option.

But I just realized, the design doesn't solve this one. The order of type checking is files -> image -> html -> rtf -> text.

If you break on image, html event will not be triggered. I will make another design. Or just write your custom listener, it's easier to deal with the order.

HuakunShen commented 1 month ago

In v1.0.1 I added a onSomethingUpdate() listener.

await onSomethingUpdate(async (updatedTypes) => {
    console.log('updated types:', updatedTypes);
    if (updatedTypes.html) {
        console.log(await readHtml());
    }
    if (updatedTypes.image) {
        const img = await readImageBase64()
    }
});

You will get {files: false, image: false, html: true, rtf: false, text: true} when you copy html and {files: false, image: true, html: true, rtf: false, text: false} when you copy image in web page.

Do not call onHTMLUpdate. Instead, read the content within the callback.

ayangweb commented 1 month ago

v1.0.1添加了一个onSomethingUpdate()听众。

await onSomethingUpdate(async (updatedTypes) => {
  console.log('updated types:', updatedTypes);
  if (updatedTypes.html) {
      console.log(await readHtml());
  }
  if (updatedTypes.image) {
      const img = await readImageBase64()
  }
});

{files: false, image: false, html: true, rtf: false, text: true}当您复制 html 和{files: false, image: true, html: true, rtf: false, text: false}复制网页中的图像时,您将获得。

不要调用onHTMLUpdate。而是读取回调中的内容。

Thanks author, I'll try it later, I'll be out here for a while! Thanks for your hard work.

ayangweb commented 1 month ago

In v1.0.1 I added a onSomethingUpdate() listener.

await onSomethingUpdate(async (updatedTypes) => {
  console.log('updated types:', updatedTypes);
  if (updatedTypes.html) {
      console.log(await readHtml());
  }
  if (updatedTypes.image) {
      const img = await readImageBase64()
  }
});

You will get {files: false, image: false, html: true, rtf: false, text: true} when you copy html and {files: false, image: true, html: true, rtf: false, text: false} when you copy image in web page.

Do not call onHTMLUpdate. Instead, read the content within the callback.

I tried this and it does work, but I'm curious to ask Does rtf mean rich text? What would it be triggered on?