Skip to content

Commit 802399a

Browse files
authored
docs(opener): add examples for None::<&str> (#2202)
closes #2200
1 parent c9acff9 commit 802399a

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

plugins/opener/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,18 @@ fn main() {
9898
.plugin(tauri_plugin_opener::init())
9999
.setup(|app| {
100100
let opener = app.opener();
101+
102+
// Opens the URL in the default browser
103+
opener.open_url("https://example.com", None::<&str>)?;
104+
// Or with a specific browser/app
101105
opener.open_url("https://example.com", Some("firefox"))?;
106+
107+
// Opens the path with the system's default app
108+
opener.open_path("/path/to/file", None::<&str>)?;
109+
// Or with a specific app
102110
opener.open_path("/path/to/file", Some("firefox"))?;
111+
112+
// Reveal a path with the system's default explorer
103113
opener.reveal_item_in_dir("/path/to/file")?;
104114
Ok(())
105115
})

plugins/opener/src/lib.rs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ pub struct Opener<R: Runtime> {
3838
impl<R: Runtime> Opener<R> {
3939
/// Open a url with a default or specific program.
4040
///
41+
/// # Examples
42+
///
43+
/// ```rust,no_run
44+
/// use tauri_plugin_opener::OpenerExt;
45+
///
46+
/// tauri::Builder::default()
47+
/// .setup(|app| {
48+
/// // open the given URL on the system default browser
49+
/// app.opener().open_url("https://github.com/tauri-apps/tauri", None::<&str>)?;
50+
/// Ok(())
51+
/// });
52+
/// ```
53+
///
4154
/// ## Platform-specific:
4255
///
4356
/// - **Android / iOS**: Always opens using default program.
@@ -48,6 +61,19 @@ impl<R: Runtime> Opener<R> {
4861

4962
/// Open a url with a default or specific program.
5063
///
64+
/// # Examples
65+
///
66+
/// ```rust,no_run
67+
/// use tauri_plugin_opener::OpenerExt;
68+
///
69+
/// tauri::Builder::default()
70+
/// .setup(|app| {
71+
/// // open the given URL on the system default browser
72+
/// app.opener().open_url("https://github.com/tauri-apps/tauri", None::<&str>)?;
73+
/// Ok(())
74+
/// });
75+
/// ```
76+
///
5177
/// ## Platform-specific:
5278
///
5379
/// - **Android / iOS**: Always opens using default program.
@@ -60,6 +86,19 @@ impl<R: Runtime> Opener<R> {
6086

6187
/// Open a path with a default or specific program.
6288
///
89+
/// # Examples
90+
///
91+
/// ```rust,no_run
92+
/// use tauri_plugin_opener::OpenerExt;
93+
///
94+
/// tauri::Builder::default()
95+
/// .setup(|app| {
96+
/// // open the given path on the system default explorer
97+
/// app.opener().open_path("/path/to/file", None::<&str>)?;
98+
/// Ok(())
99+
/// });
100+
/// ```
101+
///
63102
/// ## Platform-specific:
64103
///
65104
/// - **Android / iOS**: Always opens using default program.
@@ -74,6 +113,19 @@ impl<R: Runtime> Opener<R> {
74113

75114
/// Open a path with a default or specific program.
76115
///
116+
/// # Examples
117+
///
118+
/// ```rust,no_run
119+
/// use tauri_plugin_opener::OpenerExt;
120+
///
121+
/// tauri::Builder::default()
122+
/// .setup(|app| {
123+
/// // open the given path on the system default explorer
124+
/// app.opener().open_path("/path/to/file", None::<&str>)?;
125+
/// Ok(())
126+
/// });
127+
/// ```
128+
///
77129
/// ## Platform-specific:
78130
///
79131
/// - **Android / iOS**: Always opens using default program.
@@ -98,7 +150,7 @@ pub trait OpenerExt<R: Runtime> {
98150
fn opener(&self) -> &Opener<R>;
99151
}
100152

101-
impl<R: Runtime, T: Manager<R>> crate::OpenerExt<R> for T {
153+
impl<R: Runtime, T: Manager<R>> OpenerExt<R> for T {
102154
fn opener(&self) -> &Opener<R> {
103155
self.state::<Opener<R>>().inner()
104156
}

plugins/opener/src/open.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) fn open<P: AsRef<OsStr>, S: AsRef<str>>(path: P, with: Option<S>) ->
2626
/// tauri::Builder::default()
2727
/// .setup(|app| {
2828
/// // open the given URL on the system default browser
29-
/// tauri_plugin_opener::open_url("https://github.com/tauri-apps/tauri", None)?;
29+
/// tauri_plugin_opener::open_url("https://github.com/tauri-apps/tauri", None::<&str>)?;
3030
/// Ok(())
3131
/// });
3232
/// ```
@@ -46,8 +46,8 @@ pub fn open_url<P: AsRef<str>, S: AsRef<str>>(url: P, with: Option<S>) -> crate:
4646
/// ```rust,no_run
4747
/// tauri::Builder::default()
4848
/// .setup(|app| {
49-
/// // open the given URL on the system default browser
50-
/// tauri_plugin_opener::open_path("/path/to/file", None)?;
49+
/// // open the given URL on the system default explorer
50+
/// tauri_plugin_opener::open_path("/path/to/file", None::<&str>)?;
5151
/// Ok(())
5252
/// });
5353
/// ```

0 commit comments

Comments
 (0)