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

feat: clipboard rust guide #1475 #1622

Merged
merged 4 commits into from
Nov 6, 2023

Conversation

vasfvitor
Copy link
Contributor

What kind of changes does this PR include?

  • New or updated content

Description

  • Related to Create Clipboard guide #1475
  • There's some wording and code choices regarding Rust syntax. To facilitate I wrote the 'Read' in one way and 'Write' part in another way. To clarify, examples:

With ... to indicate that it's possible to generate multiple handles:

    .invoke_handler(tauri::generate_handler![write])

or without:

    .invoke_handler(tauri::generate_handler![write])

By the way, I don't know if there any difference between calling invoke_handle multiple times vs only one.

Use match

  let content = app.clipboard().read();
    match content {
        Ok(content) => println!("Clipboard:{:?}", content),
        Err(error) => println!("{:?}", error),
    }

or unwrap()

    let content = app.clipboard().read();
    println!("{:?}", content.unwrap());
}

Then another situation: The JavaScript part seems too crude compared to Rust. We could Improve by adding the whole function in JS. I had to add function signature in Rust because of the handle part.

Another issue is regarding how to call those functions from Rust frontend. Afaik there's Yew, Leptos and Sycamore to Rust frontend and each one would have a different way to write. The vanilla option is html/css/js.
Because of this I'm thinking in a different approach in the last step: "3. Call it from your frontend -> Tabs (Rust | JavaScript)" with links for the frameworks specific guides on how to call function from Tauri/Rust backend.

I was reading some past pr discussions but if there's anything relevant to read I appreciate. Thanks

Note: I'm still learning Rust.

@netlify
Copy link

netlify bot commented Oct 16, 2023

Deploy Preview for tauri-docs-starlight ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 18b2618
🔍 Latest deploy log https://app.netlify.com/sites/tauri-docs-starlight/deploys/65484e414d9a590008a2fc76
😎 Deploy Preview https://deploy-preview-1622--tauri-docs-starlight.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 92 (no change from production)
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@lorenzolewis
Copy link
Member

For the Rust part, I don't think that invoke_handler and bridging the function over to the JS side is needed. The user would instead just use the corresponding JS function available. Let's assume that they just want to read/write to/from the clipboard in Rust code and then they can do what they'd like from there (like we do on the JS tab).

I think that with that change in mind this could be condensed down to just one Rust code block very similar to the JS side. The goal is to really just show the basics of the function to get the user up and running with as minimal but functional code as possible.

@vasfvitor
Copy link
Contributor Author

vasfvitor commented Nov 6, 2023

It now matches the JS guide, anything else?
image

image

Copy link
Member

@lorenzolewis lorenzolewis left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you very much for this!

@lorenzolewis lorenzolewis merged commit 963d607 into tauri-apps:next Nov 6, 2023
@vasfvitor vasfvitor deleted the rs-clipboard-guide branch February 25, 2024 21:48
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.

2 participants