From b3084300de9a90e8cd575113076516499aeeb070 Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 9 Dec 2024 16:04:43 +0800 Subject: [PATCH 1/3] docs(opener): add basic usage guide to readme --- plugins/opener/README.md | 34 ++++++++++++++++++++++++++++++++ plugins/opener/guest-js/index.ts | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/plugins/opener/README.md b/plugins/opener/README.md index 82d0fea18e..d95d60394d 100644 --- a/plugins/opener/README.md +++ b/plugins/opener/README.md @@ -70,7 +70,41 @@ 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() + .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"); + }) + .plugin(tauri_plugin_opener::init()) + .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 0d92596b96..ade956a6e6 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: * From 50659f54d7afb321a9fac88c954652b975f0b370 Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 9 Dec 2024 16:10:08 +0800 Subject: [PATCH 2/3] Add missing `Ok(())` and `?` --- plugins/opener/README.md | 7 ++++--- plugins/store/README.md | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/opener/README.md b/plugins/opener/README.md index d95d60394d..ca81995c6c 100644 --- a/plugins/opener/README.md +++ b/plugins/opener/README.md @@ -97,9 +97,10 @@ fn main() { tauri::Builder::default() .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"); + 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(()) }) .plugin(tauri_plugin_opener::init()) .run(tauri::generate_context!()) diff --git a/plugins/store/README.md b/plugins/store/README.md index a285de3f2d..8a2fcbf7d2 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"); From cba84b1b5af5598980bfe90270a17dc0ed3800df Mon Sep 17 00:00:00 2001 From: Tony Date: Mon, 9 Dec 2024 16:12:33 +0800 Subject: [PATCH 3/3] Register plugin first --- plugins/opener/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/opener/README.md b/plugins/opener/README.md index ca81995c6c..5c7e7f07b9 100644 --- a/plugins/opener/README.md +++ b/plugins/opener/README.md @@ -95,6 +95,7 @@ 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"))?; @@ -102,7 +103,6 @@ fn main() { opener.reveal_item_in_dir("/path/to/file")?; Ok(()) }) - .plugin(tauri_plugin_opener::init()) .run(tauri::generate_context!()) .expect("error while running tauri application"); }