// Copyright 2019-2023 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT //! Types and functions related to shell. use std::{ffi::OsStr, path::Path}; pub(crate) fn open, S: AsRef>(path: P, with: Option) -> crate::Result<()> { match with { Some(program) => ::open::with_detached(path, program.as_ref()), None => ::open::that_detached(path), } .map_err(Into::into) } /// Opens URL with the program specified in `with`, or system default if `None`. /// /// ## Platform-specific: /// /// - **Android / iOS**: Always opens using default program. /// /// # Examples /// /// ```rust,no_run /// 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::<&str>)?; /// Ok(()) /// }); /// ``` pub fn open_url, S: AsRef>(url: P, with: Option) -> crate::Result<()> { let url = url.as_ref(); open(url, with) } /// Opens path with the program specified in `with`, or system default if `None`. /// /// ## Platform-specific: /// /// - **Android / iOS**: Always opens using default program. /// /// # Examples /// /// ```rust,no_run /// tauri::Builder::default() /// .setup(|app| { /// // open the given URL on the system default explorer /// tauri_plugin_opener::open_path("/path/to/file", None::<&str>)?; /// Ok(()) /// }); /// ``` pub fn open_path, S: AsRef>(path: P, with: Option) -> crate::Result<()> { let path = path.as_ref(); open(path, with) }