|
@@ -56,11 +56,11 @@ pub struct Capability {
|
|
|
/// Description of the capability.
|
|
|
#[serde(default)]
|
|
|
pub description: String,
|
|
|
- /// Execution context of the capability.
|
|
|
- ///
|
|
|
- /// At runtime, Tauri filters the IPC command together with the context to determine whether it is allowed or not and its scope.
|
|
|
- #[serde(default)]
|
|
|
- pub context: CapabilityContext,
|
|
|
+ /// Configure remote URLs that can use the capability permissions.
|
|
|
+ pub remote: Option<CapabilityRemote>,
|
|
|
+ /// Whether this capability is enabled for local app URLs or not. Defaults to `true`.
|
|
|
+ #[serde(default = "default_capability_local")]
|
|
|
+ pub local: bool,
|
|
|
/// List of windows that uses this capability. Can be a glob pattern.
|
|
|
///
|
|
|
/// On multiwebview windows, prefer [`Self::webviews`] for a fine grained access control.
|
|
@@ -78,6 +78,10 @@ pub struct Capability {
|
|
|
pub platforms: Vec<Target>,
|
|
|
}
|
|
|
|
|
|
+fn default_capability_local() -> bool {
|
|
|
+ true
|
|
|
+}
|
|
|
+
|
|
|
fn default_platforms() -> Vec<Target> {
|
|
|
vec![
|
|
|
Target::Linux,
|
|
@@ -88,19 +92,13 @@ fn default_platforms() -> Vec<Target> {
|
|
|
]
|
|
|
}
|
|
|
|
|
|
-/// Context of the capability.
|
|
|
+/// Configuration for remote URLs that are associated with the capability.
|
|
|
#[derive(Debug, Default, Clone, Serialize, Deserialize, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
|
|
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
-pub enum CapabilityContext {
|
|
|
- /// Capability refers to local URL usage.
|
|
|
- #[default]
|
|
|
- Local,
|
|
|
- /// Capability refers to remote usage.
|
|
|
- Remote {
|
|
|
- /// Remote domains this capability refers to. Can use glob patterns.
|
|
|
- urls: Vec<String>,
|
|
|
- },
|
|
|
+pub struct CapabilityRemote {
|
|
|
+ /// Remote domains this capability refers to. Can use glob patterns.
|
|
|
+ pub urls: Vec<String>,
|
|
|
}
|
|
|
|
|
|
/// Capability formats accepted in a capability file.
|
|
@@ -154,19 +152,14 @@ mod build {
|
|
|
use super::*;
|
|
|
use crate::{literal_struct, tokens::*};
|
|
|
|
|
|
- impl ToTokens for CapabilityContext {
|
|
|
+ impl ToTokens for CapabilityRemote {
|
|
|
fn to_tokens(&self, tokens: &mut TokenStream) {
|
|
|
- let prefix = quote! { ::tauri::utils::acl::capability::CapabilityContext };
|
|
|
-
|
|
|
- tokens.append_all(match self {
|
|
|
- Self::Remote { urls } => {
|
|
|
- let urls = vec_lit(urls, str_lit);
|
|
|
- quote! { #prefix::Remote { urls: #urls } }
|
|
|
- }
|
|
|
- Self::Local => {
|
|
|
- quote! { #prefix::Local }
|
|
|
- }
|
|
|
- });
|
|
|
+ let urls = vec_lit(&self.urls, str_lit);
|
|
|
+ literal_struct!(
|
|
|
+ tokens,
|
|
|
+ ::tauri::utils::acl::capability::CapabilityRemote,
|
|
|
+ urls
|
|
|
+ );
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -192,7 +185,8 @@ mod build {
|
|
|
fn to_tokens(&self, tokens: &mut TokenStream) {
|
|
|
let identifier = str_lit(&self.identifier);
|
|
|
let description = str_lit(&self.description);
|
|
|
- let context = &self.context;
|
|
|
+ let remote = &self.remote;
|
|
|
+ let local = self.local;
|
|
|
let windows = vec_lit(&self.windows, str_lit);
|
|
|
let permissions = vec_lit(&self.permissions, identity);
|
|
|
let platforms = vec_lit(&self.platforms, identity);
|
|
@@ -202,7 +196,8 @@ mod build {
|
|
|
::tauri::utils::acl::capability::Capability,
|
|
|
identifier,
|
|
|
description,
|
|
|
- context,
|
|
|
+ remote,
|
|
|
+ local,
|
|
|
windows,
|
|
|
permissions,
|
|
|
platforms
|