mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-09-11 07:55:34 +03:00
This commit is contained in:
parent
9db9e6c037
commit
d0d873e39a
5
.changes/open-links-mail-tel.md
Normal file
5
.changes/open-links-mail-tel.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": minor
|
||||
---
|
||||
|
||||
Added support to `mailto:` and `tel:` links on the shell API.
|
@ -2211,7 +2211,7 @@
|
||||
"description": "Defines the `shell > open` api scope.",
|
||||
"anyOf": [
|
||||
{
|
||||
"description": "If the shell open API should be enabled.\n\nIf enabled, the default validation regex (`^https?://`) is used.",
|
||||
"description": "If the shell open API should be enabled.\n\nIf enabled, the default validation regex (`^((mailto:\\w+)|(tel:\\w+)|(https?://\\w+)).+`) is used.",
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
|
@ -414,7 +414,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
||||
let shell_scope_open = match &config.tauri.allowlist.shell.open {
|
||||
ShellAllowlistOpen::Flag(false) => quote!(::std::option::Option::None),
|
||||
ShellAllowlistOpen::Flag(true) => {
|
||||
quote!(::std::option::Option::Some(#root::regex::Regex::new("^https?://").unwrap()))
|
||||
quote!(::std::option::Option::Some(#root::regex::Regex::new(r#"^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+"#).unwrap()))
|
||||
}
|
||||
ShellAllowlistOpen::Validate(regex) => match Regex::new(regex) {
|
||||
Ok(_) => quote!(::std::option::Option::Some(#root::regex::Regex::new(#regex).unwrap())),
|
||||
|
@ -1599,7 +1599,7 @@ pub struct ShellAllowlistScope(pub Vec<ShellAllowedCommand>);
|
||||
pub enum ShellAllowlistOpen {
|
||||
/// If the shell open API should be enabled.
|
||||
///
|
||||
/// If enabled, the default validation regex (`^https?://`) is used.
|
||||
/// If enabled, the default validation regex (`^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+`) is used.
|
||||
Flag(bool),
|
||||
|
||||
/// Enable the shell open API, with a custom regex that the opened path must match against.
|
||||
|
File diff suppressed because one or more lines are too long
@ -96,7 +96,7 @@
|
||||
if (target.matches('a')) {
|
||||
if (
|
||||
target.href &&
|
||||
target.href.startsWith('http') &&
|
||||
(['http://', 'https://', 'mailto:', 'tel:'].some(v => target.href.startsWith(v))) &&
|
||||
target.target === '_blank'
|
||||
) {
|
||||
window.__TAURI_INVOKE__('tauri', {
|
||||
|
@ -91,7 +91,7 @@ impl Program {
|
||||
|
||||
/// 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?://`.
|
||||
/// The path will be matched against the shell open validation regex, defaulting to `^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+`.
|
||||
/// A custom validation regex may be supplied in the config in `tauri > allowlist > scope > open`.
|
||||
///
|
||||
/// # Examples
|
||||
|
@ -301,7 +301,7 @@ impl Scope {
|
||||
/// Open a path in the default (or specified) browser.
|
||||
///
|
||||
/// The path is validated against the `tauri > allowlist > shell > open` validation regex, which
|
||||
/// defaults to `^https?://`.
|
||||
/// defaults to `^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+`.
|
||||
#[cfg(feature = "shell-open-api")]
|
||||
pub fn open(&self, path: &str, with: Option<Program>) -> Result<(), ScopeError> {
|
||||
// ensure we pass validation if the configuration has one
|
||||
|
@ -32,7 +32,7 @@
|
||||
* ### Restricting access to the {@link open | `open`} API
|
||||
*
|
||||
* On the allowlist, `open: true` means that the {@link open} API can be used with any URL,
|
||||
* as the argument is validated with the `^https?://` regex.
|
||||
* as the argument is validated with the `^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+` regex.
|
||||
* You can change that regex by changing the boolean value to a string, e.g. `open: ^https://github.com/`.
|
||||
*
|
||||
* ### Restricting access to the {@link Command | `Command`} APIs
|
||||
@ -553,7 +553,7 @@ type CommandEvent =
|
||||
*
|
||||
* @param path The path or URL to open.
|
||||
* This value is matched against the string regex defined on `tauri.conf.json > tauri > allowlist > shell > open`,
|
||||
* which defaults to `^https?://`.
|
||||
* which defaults to `^((mailto:\w+)|(tel:\w+)|(https?://\w+)).+`.
|
||||
* @param openWith The app to open the file or URL with.
|
||||
* Defaults to the system default application for the specified path type.
|
||||
*
|
||||
|
@ -2211,7 +2211,7 @@
|
||||
"description": "Defines the `shell > open` api scope.",
|
||||
"anyOf": [
|
||||
{
|
||||
"description": "If the shell open API should be enabled.\n\nIf enabled, the default validation regex (`^https?://`) is used.",
|
||||
"description": "If the shell open API should be enabled.\n\nIf enabled, the default validation regex (`^((mailto:\\w+)|(tel:\\w+)|(https?://\\w+)).+`) is used.",
|
||||
"type": "boolean"
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user