Переглянути джерело

initial namespace config definition

Lucas Nogueira 2 роки тому
батько
коміт
f8d98db9ff

+ 34 - 1
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<Namespace>,
+}
+
+/// 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<String>,
+  /// List of capabilities attached to this namespace.
+  pub capabilities: Vec<String>,
 }
 
 /// 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);
     }
   }
 }

+ 7 - 1
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"]
+  }]
 }

+ 43 - 0
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
     }
   }
 }