M0.6: command registry, guard, theme tokens, app.about and app.quit

Command trait with static spec, enabled check and run; Registry rejects
duplicate ids; Engine::execute runs every command inside the guard, which
turns panics into EngineError::Internal and keeps the engine usable.
Effects (Quit) are applied by the host. Theme tokens for Lutra Dark and
Lutra Light render as --lt-* CSS variables and a webview init script.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-14 06:40:15 +02:00
parent 50bcc95006
commit b382f9fae7
12 changed files with 758 additions and 1 deletions

View file

@ -0,0 +1,50 @@
//! The command registry, keyed by command id.
use std::collections::BTreeMap;
use crate::{Command, EngineError};
/// All registered commands, in id order.
#[derive(Default)]
pub struct Registry {
/// Commands by id.
commands: BTreeMap<&'static str, Box<dyn Command>>,
}
impl Registry {
/// Adds a command.
///
/// # Errors
/// Returns [`EngineError::Internal`] if the id is already taken; two
/// commands with one id is a programming error.
pub fn register(&mut self, command: Box<dyn Command>) -> Result<(), EngineError> {
let id = command.spec().id;
if self.commands.contains_key(id) {
return Err(EngineError::Internal(format!(
"command registered twice: {id}"
)));
}
self.commands.insert(id, command);
Ok(())
}
/// Looks a command up by id.
pub fn get(&self, id: &str) -> Option<&dyn Command> {
self.commands.get(id).map(Box::as_ref)
}
/// Iterates over the commands in id order.
pub fn iter(&self) -> impl Iterator<Item = &dyn Command> {
self.commands.values().map(Box::as_ref)
}
/// Number of registered commands.
pub fn len(&self) -> usize {
self.commands.len()
}
/// Whether no command is registered.
pub fn is_empty(&self) -> bool {
self.commands.is_empty()
}
}