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,53 @@
//! Application commands: `app.about` and `app.quit`.
use serde_json::{Value, json};
use crate::{Command, CommandSpec, Effect, EngineError, Outcome, State};
/// Product name shown in the About window and window titles.
pub const PRODUCT_NAME: &str = "Lutra";
/// Product slogan.
pub const SLOGAN: &str = "An otterly perfect IDE";
/// `app.about`: returns the product name, version and slogan.
pub struct About;
impl Command for About {
fn spec(&self) -> &CommandSpec {
&CommandSpec {
id: "app.about",
label: "About Lutra",
menu_path: Some("Help/About Lutra"),
default_shortcut: None,
params: "none; returns { name, version, slogan }",
}
}
fn run(&self, _state: &mut State, _params: Value) -> Result<Outcome, EngineError> {
Ok(Outcome::value(json!({
"name": PRODUCT_NAME,
"version": env!("CARGO_PKG_VERSION"),
"slogan": SLOGAN,
})))
}
}
/// `app.quit`: asks the host to quit the application.
pub struct Quit;
impl Command for Quit {
fn spec(&self) -> &CommandSpec {
&CommandSpec {
id: "app.quit",
label: "Quit",
menu_path: Some("File/Quit"),
default_shortcut: Some("Mod+Q"),
params: "none; returns null and the effect quit",
}
}
fn run(&self, _state: &mut State, _params: Value) -> Result<Outcome, EngineError> {
Ok(Outcome::effect(Effect::Quit))
}
}

View file

@ -0,0 +1,15 @@
//! Built-in commands, one module per area.
mod app;
use crate::{EngineError, Registry};
/// Registers every built-in command.
///
/// # Errors
/// Returns [`EngineError::Internal`] if two commands share an id.
pub fn register_builtins(registry: &mut Registry) -> Result<(), EngineError> {
registry.register(Box::new(app::About))?;
registry.register(Box::new(app::Quit))?;
Ok(())
}