From 802399a969a95c1cdd9ce8076cd1f7cbdf6d1d9e Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Fri, 13 Dec 2024 04:22:35 +0200 Subject: [PATCH] docs(opener): add examples for `None::<&str>` (#2202) closes #2200 --- plugins/opener/README.md | 10 +++++++ plugins/opener/src/lib.rs | 54 +++++++++++++++++++++++++++++++++++++- plugins/opener/src/open.rs | 6 ++--- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/plugins/opener/README.md b/plugins/opener/README.md index 5c7e7f07..71509eaa 100644 --- a/plugins/opener/README.md +++ b/plugins/opener/README.md @@ -98,8 +98,18 @@ fn main() { .plugin(tauri_plugin_opener::init()) .setup(|app| { let opener = app.opener(); + + // Opens the URL in the default browser + opener.open_url("https://example.com", None::<&str>)?; + // Or with a specific browser/app opener.open_url("https://example.com", Some("firefox"))?; + + // Opens the path with the system's default app + opener.open_path("/path/to/file", None::<&str>)?; + // Or with a specific app opener.open_path("/path/to/file", Some("firefox"))?; + + // Reveal a path with the system's default explorer opener.reveal_item_in_dir("/path/to/file")?; Ok(()) }) diff --git a/plugins/opener/src/lib.rs b/plugins/opener/src/lib.rs index 0b6c6007..1cb78b86 100644 --- a/plugins/opener/src/lib.rs +++ b/plugins/opener/src/lib.rs @@ -38,6 +38,19 @@ pub struct Opener { impl Opener { /// Open a url with a default or specific program. /// + /// # Examples + /// + /// ```rust,no_run + /// use tauri_plugin_opener::OpenerExt; + /// + /// tauri::Builder::default() + /// .setup(|app| { + /// // open the given URL on the system default browser + /// app.opener().open_url("https://github.com/tauri-apps/tauri", None::<&str>)?; + /// Ok(()) + /// }); + /// ``` + /// /// ## Platform-specific: /// /// - **Android / iOS**: Always opens using default program. @@ -48,6 +61,19 @@ impl Opener { /// Open a url with a default or specific program. /// + /// # Examples + /// + /// ```rust,no_run + /// use tauri_plugin_opener::OpenerExt; + /// + /// tauri::Builder::default() + /// .setup(|app| { + /// // open the given URL on the system default browser + /// app.opener().open_url("https://github.com/tauri-apps/tauri", None::<&str>)?; + /// Ok(()) + /// }); + /// ``` + /// /// ## Platform-specific: /// /// - **Android / iOS**: Always opens using default program. @@ -60,6 +86,19 @@ impl Opener { /// Open a path with a default or specific program. /// + /// # Examples + /// + /// ```rust,no_run + /// use tauri_plugin_opener::OpenerExt; + /// + /// tauri::Builder::default() + /// .setup(|app| { + /// // open the given path on the system default explorer + /// app.opener().open_path("/path/to/file", None::<&str>)?; + /// Ok(()) + /// }); + /// ``` + /// /// ## Platform-specific: /// /// - **Android / iOS**: Always opens using default program. @@ -74,6 +113,19 @@ impl Opener { /// Open a path with a default or specific program. /// + /// # Examples + /// + /// ```rust,no_run + /// use tauri_plugin_opener::OpenerExt; + /// + /// tauri::Builder::default() + /// .setup(|app| { + /// // open the given path on the system default explorer + /// app.opener().open_path("/path/to/file", None::<&str>)?; + /// Ok(()) + /// }); + /// ``` + /// /// ## Platform-specific: /// /// - **Android / iOS**: Always opens using default program. @@ -98,7 +150,7 @@ pub trait OpenerExt { fn opener(&self) -> &Opener; } -impl> crate::OpenerExt for T { +impl> OpenerExt for T { fn opener(&self) -> &Opener { self.state::>().inner() } diff --git a/plugins/opener/src/open.rs b/plugins/opener/src/open.rs index bbd836e3..da531472 100644 --- a/plugins/opener/src/open.rs +++ b/plugins/opener/src/open.rs @@ -26,7 +26,7 @@ pub(crate) fn open, S: AsRef>(path: P, with: Option) -> /// tauri::Builder::default() /// .setup(|app| { /// // open the given URL on the system default browser -/// tauri_plugin_opener::open_url("https://github.com/tauri-apps/tauri", None)?; +/// tauri_plugin_opener::open_url("https://github.com/tauri-apps/tauri", None::<&str>)?; /// Ok(()) /// }); /// ``` @@ -46,8 +46,8 @@ pub fn open_url, S: AsRef>(url: P, with: Option) -> crate: /// ```rust,no_run /// tauri::Builder::default() /// .setup(|app| { -/// // open the given URL on the system default browser -/// tauri_plugin_opener::open_path("/path/to/file", None)?; +/// // open the given URL on the system default explorer +/// tauri_plugin_opener::open_path("/path/to/file", None::<&str>)?; /// Ok(()) /// }); /// ```