Available on crate feature
shell-open-api
only.Expand description
Opens path or URL with the program specified in with
, or system default if None
.
The path will be matched against the shell open validation regex, defaulting to ^https?://
.
A custom validation regex may be supplied in the config in tauri > allowlist > scope > open
.
Examples
use tauri::{api::shell::open, Manager};
tauri::Builder::default()
.setup(|app| {
// open the given URL on the system default browser
open(&app.shell_scope(), "https://github.com/tauri-apps/tauri", None)?;
Ok(())
});
Examples found in repository?
src/endpoints/shell.rs (line 223)
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
fn open<R: Runtime>(
context: InvokeContext<R>,
path: String,
with: Option<String>,
) -> super::Result<()> {
use std::str::FromStr;
with
.as_deref()
// only allow pre-determined programs to be specified
.map(crate::api::shell::Program::from_str)
.transpose()
.map_err(Into::into)
// validate and open path
.and_then(|with| {
crate::api::shell::open(&context.window.state::<Scopes>().shell, path, with)
.map_err(Into::into)
})
}