From b382a4e08f9d18ee37aad0a654a98e075061bbae Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Sun, 30 Jul 2023 17:53:26 -0300 Subject: [PATCH] allow core to define plugin manifests --- core/tauri-build/src/plugin.rs | 10 ++-- core/tauri/build.rs | 9 ++++ core/tauri/capabilities/allow-event-emit.json | 5 ++ .../capabilities/allow-event-listen.json | 5 ++ examples/api/src-tauri/tauri.conf.json | 2 +- examples/api/src-tauri/tauri.namespace.lock | 50 ++++++++++++++++++- 6 files changed, 74 insertions(+), 7 deletions(-) create mode 100644 core/tauri/capabilities/allow-event-emit.json create mode 100644 core/tauri/capabilities/allow-event-listen.json diff --git a/core/tauri-build/src/plugin.rs b/core/tauri-build/src/plugin.rs index a27836934..85b3c654f 100644 --- a/core/tauri-build/src/plugin.rs +++ b/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); } } diff --git a/core/tauri/build.rs b/core/tauri/build.rs index 29ea69f97..b9bf80cdf 100644 --- a/core/tauri/build.rs +++ b/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() { diff --git a/core/tauri/capabilities/allow-event-emit.json b/core/tauri/capabilities/allow-event-emit.json new file mode 100644 index 000000000..0230840ef --- /dev/null +++ b/core/tauri/capabilities/allow-event-emit.json @@ -0,0 +1,5 @@ +{ + "id": "allow-event-emit", + "description": "Allows the event's emit function", + "features": ["emit"] +} diff --git a/core/tauri/capabilities/allow-event-listen.json b/core/tauri/capabilities/allow-event-listen.json new file mode 100644 index 000000000..8415be035 --- /dev/null +++ b/core/tauri/capabilities/allow-event-listen.json @@ -0,0 +1,5 @@ +{ + "id": "allow-event-listen", + "description": "Allows the event's listen function", + "features": ["listen"] +} diff --git a/examples/api/src-tauri/tauri.conf.json b/examples/api/src-tauri/tauri.conf.json index 39919b72d..fe1aac25b 100644 --- a/examples/api/src-tauri/tauri.conf.json +++ b/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"] }] } diff --git a/examples/api/src-tauri/tauri.namespace.lock b/examples/api/src-tauri/tauri.namespace.lock index f436c10dc..06314e583 100644 --- a/examples/api/src-tauri/tauri.namespace.lock +++ b/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" ] } ]