fix: mock context without dynamic-acl feature (#13455)

This commit is contained in:
Tony 2025-05-17 18:08:53 +08:00 committed by GitHub
parent 638804e9c4
commit 626165eeb4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 16 additions and 16 deletions

1
Cargo.lock generated
View File

@ -8570,7 +8570,6 @@ dependencies = [
"png",
"proc-macro2",
"quote",
"regex",
"semver",
"serde",
"serde_json",

View File

@ -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"

View File

@ -409,8 +409,7 @@ pub fn context_codegen(data: ContextData) -> EmbeddedAssetsResult<TokenStream> {
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) {

View File

@ -294,9 +294,9 @@ impl<R: Runtime> AssetResolver<R> {
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<Asset> {
#[cfg(dev)]

View File

@ -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<String, Manifest>,

View File

@ -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<R: Runtime, A: Assets<R>>(assets: A) -> crate::Context<R> {
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)]