Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions plugins/opener/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
})
Expand Down
54 changes: 53 additions & 1 deletion plugins/opener/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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()
}
Expand Down
6 changes: 3 additions & 3 deletions plugins/opener/src/open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
/// });
/// ```
Expand All @@ -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(())
/// });
/// ```
Expand Down
Loading