mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-09-11 07:55:34 +03:00
resolve conflicts on capability ids
This commit is contained in:
parent
13a774e0ca
commit
cb78c12db8
@ -521,19 +521,47 @@ pub fn try_build(attributes: Attributes) -> Result<()> {
|
||||
});
|
||||
|
||||
for capability in &namespace.capabilities {
|
||||
let (plugin, capability) = manifests.find_capability(capability).unwrap_or_else(|| {
|
||||
let (target_plugin, capability_id) = capability
|
||||
.split_once(':')
|
||||
.map(|(plugin, id)| (Some(plugin), id))
|
||||
.unwrap_or_else(|| (None, capability.as_str()));
|
||||
let capabilities = manifests.find_capability(capability_id);
|
||||
|
||||
if capabilities.is_empty() {
|
||||
panic!("could not find capability specification matching id {capability}")
|
||||
});
|
||||
if plugin == APP_MANIFEST_KEY {
|
||||
member_resolution.commands.extend(capability.features);
|
||||
} else {
|
||||
member_resolution.commands.extend(
|
||||
capability
|
||||
.features
|
||||
let (plugin, capability) = if let Some(target) = target_plugin {
|
||||
capabilities
|
||||
.into_iter()
|
||||
.map(|f| format!("plugin:{plugin}|{f}"))
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
.find(|(p, _)| p == target)
|
||||
.unwrap_or_else(|| {
|
||||
panic!("failed to find capability matching id {capability_id} for plugin {target}")
|
||||
})
|
||||
} else if capabilities.len() > 1 {
|
||||
panic!(
|
||||
"found a conflict on capability id {capability}, please use one of the [{}] prefixes",
|
||||
capabilities
|
||||
.iter()
|
||||
.map(|(p, _)| format!("'{p}:'"))
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ")
|
||||
);
|
||||
} else {
|
||||
// already checked that the capabilities aren't empty
|
||||
capabilities.into_iter().next().unwrap()
|
||||
};
|
||||
|
||||
if plugin == APP_MANIFEST_KEY {
|
||||
member_resolution.commands.extend(capability.features);
|
||||
} else {
|
||||
member_resolution.commands.extend(
|
||||
capability
|
||||
.features
|
||||
.into_iter()
|
||||
.map(|f| format!("plugin:{plugin}|{f}"))
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -176,21 +176,23 @@ impl From<HashMap<String, Manifest>> for ManifestMap {
|
||||
|
||||
impl ManifestMap {
|
||||
/// Finds the capability with the given identifier.
|
||||
pub fn find_capability(&self, id: &str) -> Option<(String, Capability)> {
|
||||
pub fn find_capability(&self, id: &str) -> Vec<(String, Capability)> {
|
||||
let mut capabilities = Vec::new();
|
||||
|
||||
for (plugin, manifest) in &self.0 {
|
||||
if id == format!("{DEFAULT_CAPABILITY_ID}-{plugin}") {
|
||||
return Some((
|
||||
capabilities.push((
|
||||
plugin.clone(),
|
||||
manifest.default_capability.clone().unwrap_or_default(),
|
||||
));
|
||||
}
|
||||
for capability in &manifest.capabilities {
|
||||
if capability.id == id {
|
||||
return Some((plugin.clone(), capability.clone()));
|
||||
capabilities.push((plugin.clone(), capability.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
capabilities
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user