allow core to define plugin manifests

This commit is contained in:
Lucas Nogueira 2023-07-30 17:53:26 -03:00
parent b82899b96b
commit b382a4e08f
No known key found for this signature in database
GPG Key ID: 7C32FCA95C8C95D7
6 changed files with 74 additions and 7 deletions

View File

@ -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);
}
}

View File

@ -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() {

View File

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

View File

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

View File

@ -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"]
}]
}

View File

@ -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"
]
}
]