From f8d98db9ff6eb33608e702bbbdeba1002efb4cb0 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Mon, 24 Jul 2023 22:11:18 -0300 Subject: [PATCH] initial namespace config definition --- core/tauri-utils/src/config.rs | 35 ++++++++++++++++++++- examples/api/src-tauri/tauri.conf.json | 8 ++++- tooling/cli/schema.json | 43 ++++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/core/tauri-utils/src/config.rs b/core/tauri-utils/src/config.rs index 568fa86c5..f37edd0ce 100644 --- a/core/tauri-utils/src/config.rs +++ b/core/tauri-utils/src/config.rs @@ -1916,6 +1916,27 @@ pub struct Config { /// The plugins config. #[serde(default)] pub plugins: PluginConfig, + /// The namespaces defining what capabilities are enabled. + #[serde(default)] + pub namespaces: Vec, +} + +/// A namespace defining a set of capabilities that are enabled for a given window. +#[skip_serializing_none] +#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize)] +#[cfg_attr(feature = "schema", derive(JsonSchema))] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +pub struct Namespace { + /// Identifier of this namespace. Must be unique. + /// + /// It is recommended to use `drop-` or `allow-` prefixes to ensure the rule can be easily categorized. + pub id: String, + /// Describes the namespace in a human readable format. + pub description: String, + /// The windows that can use the configuration of this namespace. + pub members: Vec, + /// List of capabilities attached to this namespace. + pub capabilities: Vec, } /// The plugin configs holds a HashMap mapping a plugin name to its configuration object. @@ -2646,6 +2667,17 @@ mod build { } } + impl ToTokens for Namespace { + fn to_tokens(&self, tokens: &mut TokenStream) { + let id = str_lit(&self.id); + let description = str_lit(&self.description); + let members = vec_lit(&self.members, str_lit); + let capabilities = vec_lit(&self.capabilities, str_lit); + + literal_struct!(tokens, Namespace, id, description, members, capabilities); + } + } + impl ToTokens for Config { fn to_tokens(&self, tokens: &mut TokenStream) { let schema = quote!(None); @@ -2653,8 +2685,9 @@ mod build { let tauri = &self.tauri; let build = &self.build; let plugins = &self.plugins; + let namespaces = vec_lit(&self.namespaces, identity); - literal_struct!(tokens, Config, schema, package, tauri, build, plugins); + literal_struct!(tokens, Config, schema, package, tauri, build, plugins, namespaces); } } } diff --git a/examples/api/src-tauri/tauri.conf.json b/examples/api/src-tauri/tauri.conf.json index fc7eef0ed..1a42acada 100644 --- a/examples/api/src-tauri/tauri.conf.json +++ b/examples/api/src-tauri/tauri.conf.json @@ -106,5 +106,11 @@ "iconAsTemplate": true, "menuOnLeftClick": false } - } + }, + "namespaces": [{ + "id": "main", + "description": "Main window namespace", + "members": ["main"], + "capabilities": ["allow-ping"] + }] } diff --git a/tooling/cli/schema.json b/tooling/cli/schema.json index 6ad6c5921..cc4bfb6d7 100644 --- a/tooling/cli/schema.json +++ b/tooling/cli/schema.json @@ -108,6 +108,14 @@ "$ref": "#/definitions/PluginConfig" } ] + }, + "namespaces": { + "description": "The namespaces defining what capabilities are enabled.", + "default": [], + "type": "array", + "items": { + "$ref": "#/definitions/Namespace" + } } }, "additionalProperties": false, @@ -2258,6 +2266,41 @@ "description": "The plugin configs holds a HashMap mapping a plugin name to its configuration object.\n\nSee more: https://tauri.app/v1/api/config#pluginconfig", "type": "object", "additionalProperties": true + }, + "Namespace": { + "description": "A namespace defining a set of capabilities that are enabled for a given window.", + "type": "object", + "required": [ + "capabilities", + "description", + "id", + "members" + ], + "properties": { + "id": { + "description": "Identifier of this namespace. Must be unique.\n\nIt is recommended to use `drop-` or `allow-` prefixes to ensure the rule can be easily categorized.", + "type": "string" + }, + "description": { + "description": "Describes the namespace in a human readable format.", + "type": "string" + }, + "members": { + "description": "The windows that can use the configuration of this namespace.", + "type": "array", + "items": { + "type": "string" + } + }, + "capabilities": { + "description": "List of capabilities attached to this namespace.", + "type": "array", + "items": { + "type": "string" + } + } + }, + "additionalProperties": false } } } \ No newline at end of file