docs(opener): add examples for `None::<&str>` (#2202)

closes #2200
pull/2205/head
Amr Bashir 6 months ago committed by GitHub
parent c9acff99c6
commit 802399a969
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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(())
})

@ -38,6 +38,19 @@ pub struct Opener<R: Runtime> {
impl<R: Runtime> Opener<R> {
/// 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<R: Runtime> Opener<R> {
/// 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<R: Runtime> Opener<R> {
/// 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<R: Runtime> Opener<R> {
/// 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<R: Runtime> {
fn opener(&self) -> &Opener<R>;
}
impl<R: Runtime, T: Manager<R>> crate::OpenerExt<R> for T {
impl<R: Runtime, T: Manager<R>> OpenerExt<R> for T {
fn opener(&self) -> &Opener<R> {
self.state::<Opener<R>>().inner()
}

@ -26,7 +26,7 @@ pub(crate) fn open<P: AsRef<OsStr>, S: AsRef<str>>(path: P, with: Option<S>) ->
/// 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<P: AsRef<str>, S: AsRef<str>>(url: P, with: Option<S>) -> 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(())
/// });
/// ```

Loading…
Cancel
Save