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

Suggestion: A rust crate About Cross-platform clipboard API (text | image | rich text | html | files | monitoring changes) #55

Closed
ChurchTao opened this issue Mar 15, 2024 · 7 comments

Comments

@ChurchTao
Copy link

I really like the stacks UI and I want it to get better. I thought my crate might be helpful to you. 😄

Let me self-recommend my crate.
Clipboard API (text | image | rich text | html | files | monitoring changes)
https://github.com/ChurchTao/clipboard-rs

@ChurchTao
Copy link
Author

@cablehead
If you need it, I can also take time to help you improve this project.

@cablehead
Copy link
Owner

cablehead commented Mar 15, 2024

Hi @ChurchTao! clipboard-rs looks really nice, particularly the way it normalizes a large number of content-type's across the different platforms.

For Stacks, I'm looking to drop one layer lower, where I want to be able surface everything a platform has to offer, in an unopinionated way. This may allow for things we couldn't imagine, as you don't really know what's possible, until you've had a chance to see the raw data.

This comment notes that Safari on macOS writes information to the clipboard for the url, and the place on page, where you copied text from: #49 (comment)

Would you have any interest (and time!?) in creating a lower level crate, (perhaps a dependent crate for clipboard-rs?) that calls the user's handler with a HashMap of the raw data available on the platform's clipboard. i.e. for macOS it'd call the handler with something that looks like this:

{
  "types": {
    "com.apple.webarchive": "YnBsaXN0MDDRAQJfEA9XZWJNYWluUmVzb3VyY2XVAwQFBgcICQoLDF5XZWJSZXNvdXJjZVVSTF8QFFdlYlJlc291cmNlRnJhbWVOYW1lXxAPV2ViUmVzb3VyY2VEYXRhXxATV2ViUmVzb3VyY2VNSU1FVHlwZV8QG1dlYlJlc291cmNlVGV4dEVuY29kaW5nTmFtZV8Qnmh0dHBzOi8vYWxleGFuZGVyb2JlbmF1ZXIuY29tL29sbG9zLyM6fjp0ZXh0PVdoaWxlJTIwYnVpbGRpbmclMjBhbmQlMjBsaXZpbmclMjBpbiUyME9MTE9TJTJDJTIwSSUyMGxlYXJuZWQlMjB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Y2N1xjNjY2Nzt9ClxkZWZ0YWI3MjAKXHBhcmRccGFyZGVmdGFiNzIwXHNhNDQ4XHBhcnRpZ2h0ZW5mYWN0b3IwCgpcZjBcZnM0NFxmc21pbGxpMjI0MDAgXGNmMiBcZXhwbmQwXGV4cG5kdHcwXGtlcm5pbmcwClxvdXRsMFxzdHJva2V3aWR0aDAgXHN0cm9rZWMyIFdoaWxlIGJ1aWxkaW5nIGFuZCBsaXZpbmcgaW4gT0xMT1MsIEkgbGVhcm5lZCBhIGZldyB0aGluZ3MgYWJvdXQgcGVyc29uYWwgc29mdHdhcmU6fQ==",
    "public.utf16-external-plain-text": "//5XAGgAaQBsAGUAIABiAHUAaQBsAGQAaQBuAGcAIABhAG4AZAAgAGwAaQB2AGkAbgBnACAAaQBuACAATwBMAEwATwBTACwAIABJACAAbABlAGEAcgBuAGUAZAAgAGEAIABmAGUAdwAgAHQAaABpAG4AZwBzACAAYQBiAG8AdQB0ACAAcABlAHIAcwBvAG4AYQBsACAAcwBvAGYAdAB3AGEAcgBlADoA",
    "public.utf8-plain-text": "V2hpbGUgYnVpbGRpbmcgYW5kIGxpdmluZyBpbiBPTExPUywgSSBsZWFybmVkIGEgZmV3IHRoaW5ncyBhYm91dCBwZXJzb25hbCBzb2Z0d2FyZTo="
  },
  "change": 6507,
  "source": "com.apple.Safari"
}

there'd be no need for image coercion, etc, at this layer, just exposing what's available, directly.

@ChurchTao
Copy link
Author

ChurchTao commented Mar 18, 2024

@cablehead
I see what you mean, but there are a few difficult points here. And it is not recommended to do so

  1. Obtaining all formats at once and performing Base64 conversion will cause a certain performance loss and unnecessary memory consumption.
  2. You may not need all the formats on the clipboard, you only need those formats such as plain text, pictures, Html and so on, if you really need other format, you can use the api available_formats()=>Vec<String> to get all formats clipboard have and use getBuffer(&str: format) to get vec[u8].
  3. changeCount is just a method of monitoring clipboard changes in macOS. In Linux and Windows, it is not monitored in this form, so there is no way to unify them into changeCount.
  4. I think the field source is great, but I need to explore the feasibility of different platforms, which I haven't explored before.

API: available_formats()

@cablehead
Copy link
Owner

Thanks for the reply @ChurchTao! I'm away this week, but will follow up more when I get back. Quickly though available_formats()=>Vec<String> may offer what I'm hoping for as-is! re, changeCount, right that makes sense. I'm not looking to get the same fields as macOS provides everywhere, rather, make what the platform offers available, and then let the user (plugin authors) work with that, as they like.

@ChurchTao
Copy link
Author

@cablehead Thanks for reply!
I understand, what you mean is that you want to get all the details returned by the platform interface as much as possible, and users can choose according to their own needs. It is indeed a great idea, which increases flexibility. However, according to my idea, through available_formats and get_buffer, at least the data is lossless, and a certain format will not be lost. I sincerely ask here, if you want to meet your needs, what form of API would you expect? When you come back when you are free, we can have a good discussion.

@cablehead
Copy link
Owner

@ChurchTao if you're able, it'd be great to have you stop by the Stacks discord, to keep chatting. No pressure though, we can keep chatting here too

@ChurchTao
Copy link
Author

👌

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

No branches or pull requests

2 participants