diff --git a/Cargo.lock b/Cargo.lock index 1bf09389..4cac7181 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6564,18 +6564,17 @@ name = "tauri-plugin-opener" version = "1.0.0" dependencies = [ "dunce", + "glob", "objc2-app-kit", "objc2-foundation", "open", - "regex", "schemars", "serde", "serde_json", "tauri", "tauri-plugin", - "thiserror", + "thiserror 2.0.3", "url", - "urlpattern", "windows 0.54.0", "zbus", ] diff --git a/Cargo.toml b/Cargo.toml index a4593f0f..f1fee043 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,6 @@ schemars = "0.8" dunce = "1" specta = "=2.0.0-rc.20" glob = "0.3" -urlpattern = "0.3" zbus = "4" #tauri-specta = "=2.0.0-rc.11" diff --git a/plugins/http/Cargo.toml b/plugins/http/Cargo.toml index 7b008c14..8c1801a3 100644 --- a/plugins/http/Cargo.toml +++ b/plugins/http/Cargo.toml @@ -25,7 +25,7 @@ tauri-plugin = { workspace = true, features = ["build"] } schemars = { workspace = true } serde = { workspace = true } url = { workspace = true } -urlpattern = { workspace = true } +urlpattern = "0.3" regex = "1" [dependencies] @@ -35,7 +35,7 @@ tauri = { workspace = true } thiserror = { workspace = true } tokio = { version = "1", features = ["sync", "macros"] } tauri-plugin-fs = { path = "../fs", version = "2.0.3" } -urlpattern = { workspace = true } +urlpattern = "0.3" regex = "1" http = "1" reqwest = { version = "0.12", default-features = false } diff --git a/plugins/opener/Cargo.toml b/plugins/opener/Cargo.toml index e5a3fcf7..bd471081 100644 --- a/plugins/opener/Cargo.toml +++ b/plugins/opener/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "tauri-plugin-opener" version = "1.0.0" +description = "Open files and URLs using their default application." edition = { workspace = true } authors = { workspace = true } license = { workspace = true } @@ -26,8 +27,6 @@ ios = { level = "partial", notes = "Only allows to open URLs via `open`" } tauri-plugin = { workspace = true, features = ["build"] } schemars = { workspace = true } serde = { workspace = true } -urlpattern = { workspace = true } -regex = "1" [dependencies] serde = { workspace = true } @@ -35,9 +34,8 @@ serde_json = { workspace = true } tauri = { workspace = true } thiserror = { workspace = true } open = { version = "5", features = ["shellexecute-on-windows"] } -urlpattern = { workspace = true } -regex = "1" url = { workspace = true } +glob = { workspace = true } [target."cfg(windows)".dependencies] dunce = { workspace = true } diff --git a/plugins/opener/build.rs b/plugins/opener/build.rs index 6bccbdd9..42926233 100644 --- a/plugins/opener/build.rs +++ b/plugins/opener/build.rs @@ -15,15 +15,12 @@ mod scope; enum OpenerScopeEntry { Url { /// A URL that can be opened by the webview when using the Opener APIs. - /// Wildcards can be used following the URL pattern standard. /// - /// See [the URL Pattern spec](https://urlpattern.spec.whatwg.org/) for more information. + /// Wildcards can be used following the UNIX glob pattern. /// /// Examples: /// - /// - "https://*" : allows all HTTPS origin on port 443 - /// - /// - "https://*:*" : allows all HTTPS origin on any port + /// - "https://*" : allows all HTTPS origin /// /// - "https://*.github.com/tauri-apps/tauri": allows any subdomain of "github.com" with the "tauri-apps/api" path /// diff --git a/plugins/opener/package.json b/plugins/opener/package.json index b3490ad1..c3dc314e 100644 --- a/plugins/opener/package.json +++ b/plugins/opener/package.json @@ -1,6 +1,7 @@ { "name": "@tauri-apps/plugin-opener", "version": "1.0.0", + "description": "Open files and URLs using their default application.", "license": "MIT OR Apache-2.0", "authors": [ "Tauri Programme within The Commons Conservancy" diff --git a/plugins/opener/permissions/allow-default-urls.toml b/plugins/opener/permissions/allow-default-urls.toml index cad02770..93495b89 100644 --- a/plugins/opener/permissions/allow-default-urls.toml +++ b/plugins/opener/permissions/allow-default-urls.toml @@ -11,7 +11,7 @@ url = "mailto:*" url = "tel:*" [[permission.scope.allow]] -url = "http://*:*" +url = "http://*" [[permission.scope.allow]] -url = "https://*:*" +url = "https://*" diff --git a/plugins/opener/src/lib.rs b/plugins/opener/src/lib.rs index 48936874..1ad71c47 100644 --- a/plugins/opener/src/lib.rs +++ b/plugins/opener/src/lib.rs @@ -73,9 +73,9 @@ pub fn init() -> TauriPlugin { .js_init_script(include_str!("init-iife.js").to_string()) .setup(|app, _api| { #[cfg(target_os = "android")] - let handle = api.register_android_plugin(PLUGIN_IDENTIFIER, "OpenerPlugin")?; + let handle = _api.register_android_plugin(PLUGIN_IDENTIFIER, "OpenerPlugin")?; #[cfg(target_os = "ios")] - let handle = api.register_ios_plugin(init_plugin_opener)?; + let handle = _api.register_ios_plugin(init_plugin_opener)?; app.manage(Opener { app: app.clone(), diff --git a/plugins/opener/src/reveal_item_in_dir.rs b/plugins/opener/src/reveal_item_in_dir.rs index 70f6cc75..fbd91e29 100644 --- a/plugins/opener/src/reveal_item_in_dir.rs +++ b/plugins/opener/src/reveal_item_in_dir.rs @@ -183,5 +183,7 @@ mod imp { let workspace = NSWorkspace::new(); workspace.activateFileViewerSelectingURLs(&urls); } + + Ok(()) } } diff --git a/plugins/opener/src/scope.rs b/plugins/opener/src/scope.rs index ae325416..b5199303 100644 --- a/plugins/opener/src/scope.rs +++ b/plugins/opener/src/scope.rs @@ -7,37 +7,15 @@ use std::{marker::PhantomData, path::PathBuf, sync::Arc}; use tauri::{ipc::ScopeObject, utils::acl::Value, AppHandle, Manager, Runtime}; use url::Url; -use urlpattern::UrlPatternMatchInput; use crate::{scope_entry::EntryRaw, Error}; #[derive(Debug)] pub enum Entry { - Url(Box), + Url(glob::Pattern), Path(Option), } -fn parse_url_pattern( - s: &str, -) -> std::result::Result { - let mut init = urlpattern::UrlPatternInit::parse_constructor_string::(s, None)?; - if init.search.as_ref().map(|p| p.is_empty()).unwrap_or(true) { - init.search.replace("*".to_string()); - } - if init.hash.as_ref().map(|p| p.is_empty()).unwrap_or(true) { - init.hash.replace("*".to_string()); - } - if init - .pathname - .as_ref() - .map(|p| p.is_empty() || p == "/") - .unwrap_or(true) - { - init.pathname.replace("*".to_string()); - } - urlpattern::UrlPattern::parse(init, Default::default()) -} - impl ScopeObject for Entry { type Error = Error; @@ -48,14 +26,10 @@ impl ScopeObject for Entry { serde_json::from_value(raw.into()) .and_then(|raw| { let entry = match raw { - EntryRaw::Url { url } => { - let url_pattern = parse_url_pattern(&url).map_err(|e| { - serde::de::Error::custom(format!( - "`{url}` is not a valid URL pattern: {e}" - )) - })?; - Entry::Url(Box::new(url_pattern)) - } + EntryRaw::Url { url } => Entry::Url( + glob::Pattern::new(&url) + .map_err(|e| serde::de::Error::custom(e.to_string()))?, + ), EntryRaw::Path { path } => { let path = match app.path().parse(path) { Ok(path) => Some(path), @@ -106,18 +80,14 @@ impl<'a, R: Runtime, M: Manager> Scope<'a, R, M> { pub fn is_url_allowed(&self, url: Url) -> bool { let denied = self.denied.iter().any(|entry| match entry.as_ref() { - Entry::Url(url_pattern) => url_pattern - .test(UrlPatternMatchInput::Url(url.clone())) - .unwrap_or_default(), + Entry::Url(url_pattern) => url_pattern.matches(url.as_str()), Entry::Path { .. } => false, }); if denied { false } else { self.allowed.iter().any(|entry| match entry.as_ref() { - Entry::Url(url_pattern) => url_pattern - .test(UrlPatternMatchInput::Url(url.clone())) - .unwrap_or_default(), + Entry::Url(url_pattern) => url_pattern.matches(url.as_str()), Entry::Path { .. } => false, }) }