feat(layout): supporte la création de layouts plugins (customPluginLayout)
Étend le flux de création de layout backend (DTO, usecases, store) et le frontend (sélecteur, adaptateurs, LayoutTabs/LayoutGrid) pour permettre d'ouvrir un layout déclaré par un plugin installé (ex. Android Health), sans passer par le message bloquant "extension backend pas encore livrée". Ticket #141 — QA vert. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@ -4,12 +4,18 @@
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use domain::ports::{EventBus, FileSystem, IdGenerator, ProjectStore};
|
||||
use domain::ports::{
|
||||
EventBus, FileSystem, IdGenerator, PluginManifestValidator, PluginPackageStore,
|
||||
PluginRegistryStore, ProjectStore,
|
||||
};
|
||||
use domain::{DomainEvent, LayoutId, ProjectId};
|
||||
|
||||
use crate::error::AppError;
|
||||
|
||||
use super::store::{default_tree, persist_doc, resolve_doc, LayoutKind, NamedLayout};
|
||||
use super::store::{
|
||||
default_tree, persist_doc, plugin_layout_tree, resolve_doc, LayoutKind, NamedLayout,
|
||||
};
|
||||
use crate::plugin::runtime_plugin_from_entry;
|
||||
|
||||
/// Lightweight descriptor of a named layout (no tree), for the layouts tab bar.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
@ -70,7 +76,7 @@ impl ListLayouts {
|
||||
.map(|l| LayoutInfo {
|
||||
id: l.id,
|
||||
name: l.name.clone(),
|
||||
kind: l.kind,
|
||||
kind: l.kind.clone(),
|
||||
})
|
||||
.collect(),
|
||||
active_id: doc.active_id,
|
||||
@ -106,6 +112,9 @@ pub struct CreateLayout {
|
||||
fs: Arc<dyn FileSystem>,
|
||||
ids: Arc<dyn IdGenerator>,
|
||||
events: Arc<dyn EventBus>,
|
||||
packages: Arc<dyn PluginPackageStore>,
|
||||
registry: Arc<dyn PluginRegistryStore>,
|
||||
validator: Arc<dyn PluginManifestValidator>,
|
||||
}
|
||||
|
||||
impl CreateLayout {
|
||||
@ -116,12 +125,18 @@ impl CreateLayout {
|
||||
fs: Arc<dyn FileSystem>,
|
||||
ids: Arc<dyn IdGenerator>,
|
||||
events: Arc<dyn EventBus>,
|
||||
packages: Arc<dyn PluginPackageStore>,
|
||||
registry: Arc<dyn PluginRegistryStore>,
|
||||
validator: Arc<dyn PluginManifestValidator>,
|
||||
) -> Self {
|
||||
Self {
|
||||
store,
|
||||
fs,
|
||||
ids,
|
||||
events,
|
||||
packages,
|
||||
registry,
|
||||
validator,
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,13 +152,23 @@ impl CreateLayout {
|
||||
}
|
||||
let project = self.store.load_project(input.project_id).await?;
|
||||
let mut doc = resolve_doc(self.fs.as_ref(), &project).await?;
|
||||
if let LayoutKind::Plugin { plugin_origin, .. } = &input.kind {
|
||||
self.ensure_runtime_layout_is_active(plugin_origin).await?;
|
||||
}
|
||||
|
||||
let id = LayoutId::from_uuid(self.ids.new_uuid());
|
||||
let tree = match &input.kind {
|
||||
LayoutKind::Terminal | LayoutKind::GitGraph => default_tree(),
|
||||
LayoutKind::Plugin {
|
||||
plugin_origin,
|
||||
state,
|
||||
} => plugin_layout_tree(plugin_origin, state.clone()),
|
||||
};
|
||||
doc.layouts.push(NamedLayout {
|
||||
id,
|
||||
name: name.to_owned(),
|
||||
kind: input.kind,
|
||||
tree: default_tree(),
|
||||
tree,
|
||||
});
|
||||
doc.active_id = id; // a freshly-created layout becomes active.
|
||||
|
||||
@ -153,6 +178,42 @@ impl CreateLayout {
|
||||
});
|
||||
Ok(CreateLayoutOutput { layout_id: id })
|
||||
}
|
||||
|
||||
async fn ensure_runtime_layout_is_active(
|
||||
&self,
|
||||
origin: &super::store::PluginLayoutOrigin,
|
||||
) -> Result<(), AppError> {
|
||||
let registry = self
|
||||
.registry
|
||||
.load_registry()
|
||||
.await
|
||||
.map_err(|e| AppError::Store(e.to_string()))?;
|
||||
for entry in registry.plugins {
|
||||
if entry.id != origin.plugin_id || !entry.lifecycle_state.is_runtime_active() {
|
||||
continue;
|
||||
}
|
||||
let runtime =
|
||||
runtime_plugin_from_entry(self.packages.as_ref(), self.validator.as_ref(), entry)
|
||||
.await?;
|
||||
if runtime
|
||||
.contributes
|
||||
.layouts
|
||||
.iter()
|
||||
.any(|layout| layout.layout_type == origin.layout_type)
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
return Err(AppError::Invalid(format!(
|
||||
"plugin `{}` does not contribute layout `{}`",
|
||||
origin.plugin_id.as_str(),
|
||||
origin.layout_type.as_str()
|
||||
)));
|
||||
}
|
||||
Err(AppError::Invalid(format!(
|
||||
"plugin `{}` is not active at runtime",
|
||||
origin.plugin_id.as_str()
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user