tauri-apps / tauri-docs

The source for all Tauri project documentation.
https://tauri.app
MIT License
774 stars 565 forks source link

Mistake in guide about clipboard plugin #2412

Closed pan-grayza closed 1 week ago

pan-grayza commented 1 month ago

Discussed in https://github.com/tauri-apps/tauri/discussions/10290

Originally posted by **pan-grayza** July 15, 2024 Here are [docs](https://v2.tauri.app/plugin/clipboard/). Code from guide: ```Rust use tauri_plugin_clipboard_manager::ClipboardExt; // Write content to clipboard let clipboard_content = tauri_plugin_clipboard_manager::ClipKind::PlainText { label: Some("Label".to_string()), text: "Tauri is awesome!".to_string(), }; app.clipboard().write(clipboard_content).unwrap(); // Read content from clipboard let content = app.clipboard().read(); println!("{:?}", content.unwrap()); // Prints "Tauri is awesome!" to the terminal ``` it needs to be `write_text()` and `read_text()` instead of `write()` and `read()` [plugin code](https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/clipboard-manager/src/commands.rs) The question is, where are `app` and `ClipKind` appears from? `ClipKind` does not exists in that path And why we are importing `use tauri_plugin_clipboard_manager::ClipboardExt;` when we are not it using anywhere?
FabianLars commented 1 month ago

it needs to be write_text() and read_text() instead of write() and read() plugin code

Good catch, we didn't update that when we updated the apis a few months ago.

The question is, where are app appears from?

Copy paste from the linked discussion: "app is supposed to be an AppHandle instance which you have access to in the setup hook or in commands via https://v2.tauri.app/develop/calling-rust/#accessing-an-apphandle-in-commands"

We need to make this clearer somehow, so thanks for the feedback.

The question is, where are ClipKind appears from?

ClipKind is also from before the api update and does not exist anymore.

And why we are importing use tauri_plugin_clipboard_manager::ClipboardExt; when we are not it using anywhere?

This makes the app.clipboard() call possible.