M1.9a: engine dirs and settings backend

EngineConfig and Engine::with_config; the desktop resolves Tauri's app
config and data dirs. Settings model (appearance.theme, editor.fontSize,
ui.language) with typed validation, persistence in settings.json via
write_atomic (1 MiB cap, unknown keys kept, corrupt file backed up with a
warning notification), settings.list/get/set/reset, settingsChanged and
notification events. Property test over random settings.json content,
control-channel test for persistence and corrupt-file recovery.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-16 15:23:43 +02:00
parent 851d438e2a
commit f9357ee4b5
17 changed files with 1406 additions and 41 deletions

View file

@ -14,9 +14,18 @@ use std::path::{Path, PathBuf};
use std::sync::Mutex;
use lutra_control::{Backend, EventSink, Subscribers};
use lutra_engine::{CommandInfo, Effect, Engine, EngineError};
use lutra_engine::{CommandInfo, Effect, Engine, EngineConfig, EngineError};
use serde_json::Value;
/// Engine directories inside `root` (`root/config`, `root/data`), for
/// [`Engine::with_config`] and [`EngineBackend::with_config`] in tests.
pub fn engine_config(root: &Path) -> EngineConfig {
EngineConfig {
config_dir: root.join("config"),
data_dir: root.join("data"),
}
}
/// A control [`Backend`] over a bare engine, without a window.
///
/// Effects are recorded instead of applied; events are published to
@ -34,10 +43,22 @@ pub struct EngineBackend {
}
impl EngineBackend {
/// A backend with the built-in commands.
/// A backend with the built-in commands and no persistence.
pub fn new() -> Self {
Self::with_engine(Engine::new().unwrap())
}
/// A backend whose engine stores its files in `config`, like the
/// desktop app. Events queued while the engine started (a settings
/// warning) stay queued and arrive with the first command or pump.
pub fn with_config(config: EngineConfig) -> Self {
Self::with_engine(Engine::with_config(config).unwrap())
}
/// A backend around an existing engine.
pub fn with_engine(engine: Engine) -> Self {
Self {
engine: Mutex::new(Engine::new().unwrap()),
engine: Mutex::new(engine),
effects: Mutex::new(Vec::new()),
screenshots: Mutex::new(Vec::new()),
subscribers: Subscribers::default(),