Browse Source

allow core to define plugin manifests

Lucas Nogueira 2 years ago
parent
commit
b382a4e08f

+ 6 - 4
core/tauri-build/src/plugin.rs

@@ -20,10 +20,14 @@ pub fn set_manifest(manifest: Manifest) {
     .expect(
       "missing OUT_DIR environment variable.. are you sure you are running this on a build script?",
     )
-    .join("plugin-manifest.json");
+    .join(format!("{}-plugin-manifest.json", manifest.plugin));
   write(&manifest_path, manifest_str).expect("failed to save manifest file");
 
-  println!("cargo:{PLUGIN_METADATA_KEY}={}", manifest_path.display());
+  println!(
+    "cargo:{}_{PLUGIN_METADATA_KEY}={}",
+    manifest.plugin,
+    manifest_path.display()
+  );
 }
 
 pub(crate) fn manifests() -> ManifestMap {
@@ -34,14 +38,12 @@ pub(crate) fn manifests() -> ManifestMap {
     if let Some(_plugin_crate_name) = key
       .strip_prefix("DEP_")
       .and_then(|v| v.strip_suffix(&format!("_{PLUGIN_METADATA_KEY}")))
-      .map(|p| p.to_lowercase())
     {
       let plugin_manifest_path = PathBuf::from(value);
       let plugin_manifest_str =
         read_to_string(&plugin_manifest_path).expect("failed to read plugin manifest");
       let manifest: Manifest =
         serde_json::from_str(&plugin_manifest_str).expect("failed to deserialize plugin manifest");
-
       manifests.insert(manifest.plugin.clone(), manifest);
     }
   }

+ 9 - 0
core/tauri/build.rs

@@ -131,6 +131,15 @@ fn main() {
       println!("cargo:ios_library_path={}", lib_path.display());
     }
   }
+
+  tauri_build::plugin::set_manifest(
+    tauri_build::plugin::Manifest::new("event")
+      .features(["emit", "listen"])
+      .capability(include_str!("./capabilities/allow-event-emit.json"))
+      .capability(include_str!("./capabilities/allow-event-listen.json")),
+  );
+
+  tauri_build::plugin::set_manifest(tauri_build::plugin::Manifest::new("path"));
 }
 
 fn add_manifest() {

+ 5 - 0
core/tauri/capabilities/allow-event-emit.json

@@ -0,0 +1,5 @@
+{
+  "id": "allow-event-emit",
+  "description": "Allows the event's emit function",
+  "features": ["emit"]
+}

+ 5 - 0
core/tauri/capabilities/allow-event-listen.json

@@ -0,0 +1,5 @@
+{
+  "id": "allow-event-listen",
+  "description": "Allows the event's listen function",
+  "features": ["listen"]
+}

+ 1 - 1
examples/api/src-tauri/tauri.conf.json

@@ -111,6 +111,6 @@
     "id": "main",
     "description": "Main window namespace",
     "members": ["main"],
-    "capabilities": ["allow-all-api-commands", "allow-ping"]
+    "capabilities": ["allow-all-api-commands", "allow-ping", "allow-event-emit", "allow-event-listen"]
   }]
 }

+ 48 - 2
examples/api/src-tauri/tauri.namespace.lock

@@ -9,11 +9,48 @@
       ],
       "capabilities": [
         "allow-all-api-commands",
-        "allow-ping"
+        "allow-ping",
+        "allow-event-emit",
+        "allow-event-listen"
       ]
     }
   ],
   "plugins": {
+    "event": {
+      "plugin": "event",
+      "default_capability": null,
+      "capabilities": [
+        {
+          "id": "allow-event-emit",
+          "component": null,
+          "description": "Allows the event's emit function",
+          "features": [
+            "emit"
+          ],
+          "scope": {
+            "allowed": [],
+            "blocked": []
+          }
+        },
+        {
+          "id": "allow-event-listen",
+          "component": null,
+          "description": "Allows the event's listen function",
+          "features": [
+            "listen"
+          ],
+          "scope": {
+            "allowed": [],
+            "blocked": []
+          }
+        }
+      ],
+      "features": [
+        "emit",
+        "listen"
+      ],
+      "scope_type": []
+    },
     "__app__": {
       "default_capability": null,
       "capabilities": [
@@ -34,6 +71,13 @@
       "features": [],
       "scope_type": []
     },
+    "path": {
+      "plugin": "path",
+      "default_capability": null,
+      "capabilities": [],
+      "features": [],
+      "scope_type": []
+    },
     "sample": {
       "plugin": "sample",
       "default_capability": {
@@ -74,7 +118,9 @@
       "commands": [
         "log_operation",
         "perform_request",
-        "plugin:sample|ping"
+        "plugin:sample|ping",
+        "plugin:event|emit",
+        "plugin:event|listen"
       ]
     }
   ]