From f7ad349ed256e9c19cbfc3e6620ad53d1d25548a Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Mon, 9 Dec 2024 18:18:12 +0800 Subject: [PATCH] docs(opener): add basic usage guide to readme (#2167) * docs(opener): add basic usage guide to readme * Add missing `Ok(())` and `?` * Register plugin first --- plugins/opener/README.md | 35 ++++++++++++++++++++++++++++++++ plugins/opener/guest-js/index.ts | 2 +- plugins/store/README.md | 1 + 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/plugins/opener/README.md b/plugins/opener/README.md index 82d0fea1..5c7e7f07 100644 --- a/plugins/opener/README.md +++ b/plugins/opener/README.md @@ -70,7 +70,42 @@ fn main() { Afterwards all the plugin's APIs are available through the JavaScript guest bindings: ```javascript +import { openUrl, openPath, revealItemInDir } from '@tauri-apps/plugin-opener' +// Opens the URL in the default browser +await openUrl('https://example.com') +// Or with a specific browser/app +await openUrl('https://example.com', 'firefox') + +// Opens the path with the system's default app +await openPath('/path/to/file') +// Or with a specific app +await openPath('/path/to/file', 'firefox') + +// Reveal a path with the system's default explorer +await revealItemInDir('/path/to/file') +``` + +### Usage from Rust + +You can also use those APIs from Rust: + +```rust +use tauri_plugin_opener::OpenerExt; + +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_opener::init()) + .setup(|app| { + let opener = app.opener(); + opener.open_url("https://example.com", Some("firefox"))?; + opener.open_path("/path/to/file", Some("firefox"))?; + opener.reveal_item_in_dir("/path/to/file")?; + Ok(()) + }) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); +} ``` ## Contributing diff --git a/plugins/opener/guest-js/index.ts b/plugins/opener/guest-js/index.ts index 0d92596b..ade956a6 100644 --- a/plugins/opener/guest-js/index.ts +++ b/plugins/opener/guest-js/index.ts @@ -71,7 +71,7 @@ export async function openPath(path: string, openWith?: string): Promise { } /** - * Reveal a path the system's default explorer. + * Reveal a path with the system's default explorer. * * #### Platform-specific: * diff --git a/plugins/store/README.md b/plugins/store/README.md index a285de3f..8a2fcbf7 100644 --- a/plugins/store/README.md +++ b/plugins/store/README.md @@ -128,6 +128,7 @@ fn main() { // Note that values must be serde_json::Value instances, // otherwise, they will not be compatible with the JavaScript bindings. store.set("a".to_string(), json!("b")); + Ok(()) }) .run(tauri::generate_context!()) .expect("error while running tauri application");