From 626165eeb4e2f0fb7699d2ed4753e6ce6d91ac88 Mon Sep 17 00:00:00 2001 From: Tony <68118705+Legend-Master@users.noreply.github.com> Date: Sat, 17 May 2025 18:08:53 +0800 Subject: [PATCH] fix: mock context without `dynamic-acl` feature (#13455) --- Cargo.lock | 1 - crates/tauri-codegen/Cargo.toml | 1 - crates/tauri-codegen/src/context.rs | 3 +-- crates/tauri/src/app.rs | 4 ++-- crates/tauri/src/ipc/authority.rs | 19 +++++++++++-------- crates/tauri/src/test/mod.rs | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d01225101..2da1af7cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8570,7 +8570,6 @@ dependencies = [ "png", "proc-macro2", "quote", - "regex", "semver", "serde", "serde_json", diff --git a/crates/tauri-codegen/Cargo.toml b/crates/tauri-codegen/Cargo.toml index f6144ef25..187cd84ef 100644 --- a/crates/tauri-codegen/Cargo.toml +++ b/crates/tauri-codegen/Cargo.toml @@ -28,7 +28,6 @@ walkdir = "2" brotli = { version = "8", optional = true, default-features = false, features = [ "std", ] } -regex = { version = "1", optional = true } uuid = { version = "1", features = ["v4"] } semver = "1" ico = "0.4" diff --git a/crates/tauri-codegen/src/context.rs b/crates/tauri-codegen/src/context.rs index be519a2d5..dc79df857 100644 --- a/crates/tauri-codegen/src/context.rs +++ b/crates/tauri-codegen/src/context.rs @@ -409,8 +409,7 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult { identity, ); - let runtime_authority = - quote!(#root::runtime_acl!(#root::ipc::RuntimeAuthority::new, #acl_tokens, #resolved)); + let runtime_authority = quote!(#root::runtime_authority!(#acl_tokens, #resolved)); let plugin_global_api_scripts = if config.app.with_global_tauri { if let Some(scripts) = tauri_utils::plugin::read_global_api_scripts(&out_dir) { diff --git a/crates/tauri/src/app.rs b/crates/tauri/src/app.rs index 08f9893b3..eba237315 100644 --- a/crates/tauri/src/app.rs +++ b/crates/tauri/src/app.rs @@ -294,9 +294,9 @@ impl AssetResolver { self.get_for_scheme(path, use_https_scheme) } - /// Same as [AssetResolver::get] but resolves the custom protocol scheme based on a parameter. + /// Same as [`AssetResolver::get`] but resolves the custom protocol scheme based on a parameter. /// - /// - `use_https_scheme`: If `true` when using [`Pattern::Isolation`](tauri::Pattern::Isolation), + /// - `use_https_scheme`: If `true` when using [`Pattern::Isolation`](crate::Pattern::Isolation), /// the csp header will contain `https://tauri.localhost` instead of `http://tauri.localhost` pub fn get_for_scheme(&self, path: String, use_https_scheme: bool) -> Option { #[cfg(dev)] diff --git a/crates/tauri/src/ipc/authority.rs b/crates/tauri/src/ipc/authority.rs index 656857dc3..8bb81e398 100644 --- a/crates/tauri/src/ipc/authority.rs +++ b/crates/tauri/src/ipc/authority.rs @@ -66,7 +66,7 @@ impl Origin { } } -/// This is used internally by [`crate::generate_handler!`] +/// This is used internally by [`crate::generate_handler!`] for constructing [`RuntimeAuthority`] /// to only include the raw ACL when it's needed /// /// ## Stability @@ -77,13 +77,13 @@ impl Origin { #[cfg(any(feature = "dynamic-acl", debug_assertions))] #[doc(hidden)] #[macro_export] -macro_rules! runtime_acl { - ($func:path, $acl:expr, $resolved_acl:expr) => { - $func($acl, $resolved_acl) +macro_rules! runtime_authority { + ($acl:expr, $resolved_acl:expr) => { + $crate::ipc::RuntimeAuthority::new($acl, $resolved_acl) }; } -/// This is used internally by [`crate::generate_handler!`] +/// This is used internally by [`crate::generate_handler!`] for constructing [`RuntimeAuthority`] /// to only include the raw ACL when it's needed /// /// ## Stability @@ -94,13 +94,16 @@ macro_rules! runtime_acl { #[cfg(not(any(feature = "dynamic-acl", debug_assertions)))] #[doc(hidden)] #[macro_export] -macro_rules! runtime_acl { - ($func:path, $_acl:expr, $resolved_acl:expr) => { - $func($resolved_acl) +macro_rules! runtime_authority { + ($_acl:expr, $resolved_acl:expr) => { + $crate::ipc::RuntimeAuthority::new($resolved_acl) }; } impl RuntimeAuthority { + /// Contruct a new [`RuntimeAuthority`] from the ACL + /// + /// **Please prefer using the [`runtime_authority`] macro instead of calling this directly** #[doc(hidden)] pub fn new( #[cfg(any(feature = "dynamic-acl", debug_assertions))] acl: BTreeMap, diff --git a/crates/tauri/src/test/mod.rs b/crates/tauri/src/test/mod.rs index e8ff1bdc3..6c1311bc3 100644 --- a/crates/tauri/src/test/mod.rs +++ b/crates/tauri/src/test/mod.rs @@ -59,7 +59,7 @@ use serialize_to_javascript::DefaultTemplate; use std::{borrow::Cow, collections::HashMap, fmt::Debug}; use crate::{ - ipc::{InvokeError, InvokeResponse, InvokeResponseBody, RuntimeAuthority}, + ipc::{InvokeError, InvokeResponse, InvokeResponseBody}, webview::InvokeRequest, App, Assets, Builder, Context, Pattern, Runtime, Webview, }; @@ -139,7 +139,7 @@ pub fn mock_context>(assets: A) -> crate::Context { crate_name: "test", }, pattern: Pattern::Brownfield, - runtime_authority: RuntimeAuthority::new(Default::default(), Resolved::default()), + runtime_authority: crate::runtime_authority!(Default::default(), Resolved::default()), plugin_global_api_scripts: None, #[cfg(dev)]