M1.10: light theme, live theme switching, editor tokens

- theme::LIGHT next to DARK with the 10 new tokens (editor selection,
  active line, cursor, gutter, match, font size, tab active/modified,
  notice); light fg-muted, accent and error darkened for WCAG AA
- theme.list, theme.systemPreference, themeChanged event when the
  resolved theme changes (settings.set/reset appearance.theme, or the
  OS preference in system mode)
- desktop init script and window background from the stored setting;
  system mode uses a prefers-color-scheme media query for the first frame
- ui/src/theme.ts applies tokens to :root and color-scheme live; editor,
  tabs and notice drop their var() fallbacks
- Vitest WCAG AA contrast check against a Rust-maintained snapshot,
  DOM tests, headless control-channel test
- docs: architecture Themes, parity rows, ui-parity, gaps, roadmaps

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-10-16 15:49:23 +02:00
parent 1ab448de4d
commit cde6e119c6
29 changed files with 1192 additions and 72 deletions

View file

@ -1,6 +1,7 @@
//! The Lutra desktop app (layer L6): a Tauri 2 shell around the engine.
//!
//! Builds the main window with the theme tokens injected before first paint,
//! Builds the main window with the stored theme's tokens injected before
//! first paint,
//! bridges frontend IPC to engine commands and engine events to the window
//! (see [`host`]), opens the project given on the command line, and
//! optionally serves the JSON control channel (`--control PORT`).
@ -59,7 +60,6 @@ fn main() -> ExitCode {
fn run(args: &args::Args) -> Result<(), String> {
let slot: Arc<OnceLock<Arc<Host>>> = Arc::new(OnceLock::new());
let setup_slot = slot.clone();
let theme = theme::DARK;
let initial_path = args.path.clone();
let app = tauri::Builder::default()
.plugin(tauri_plugin_dialog::init())
@ -71,15 +71,19 @@ fn run(args: &args::Args) -> Result<(), String> {
.setup(move |app| {
let setup_host = setup_slot.get().ok_or("the host is not ready")?;
setup_host.attach(app.handle().clone());
let setting = stored_theme(setup_host);
let mut window = WebviewWindowBuilder::new(app, MAIN_WINDOW, WebviewUrl::default())
.title(WINDOW_TITLE)
.inner_size(1200.0, 800.0)
.min_inner_size(640.0, 400.0)
.initialization_script(theme::init_script(&theme));
if let Some(color) = token_color(&theme, "bg") {
.initialization_script(theme::init_script(&setting));
if let Some(color) = token_color(&theme::resolve(&setting, None), "bg") {
window = window.background_color(color);
}
window.build()?;
let window = window.build()?;
if setting == theme::SYSTEM {
follow_system_background(&window);
}
if let Some(path) = &initial_path
&& let Err(e) = setup_host.open_project(path)
{
@ -139,6 +143,36 @@ fn log_startup_events(events: &[Event]) {
}
}
/// The stored `appearance.theme` value, `system` if it cannot be read.
fn stored_theme(host: &Host) -> String {
host.run(
"settings.get",
serde_json::json!({ "keys": ["appearance.theme"] }),
)
.ok()
.and_then(|v| {
v.get("values")?
.get("appearance.theme")?
.as_str()
.map(str::to_string)
})
.unwrap_or_else(|| theme::SYSTEM.to_string())
}
/// In "system" mode, sets the window background to the theme the OS
/// prefers; the page itself follows the OS through the init script's
/// `prefers-color-scheme` query. Failures are ignored: the background only
/// shows before the first paint, and the dark default stays.
fn follow_system_background(window: &tauri::WebviewWindow) {
let Ok(os) = window.theme() else {
return;
};
let resolved = theme::resolve(theme::SYSTEM, Some(os == tauri::Theme::Dark));
if let Some(color) = token_color(&resolved, "bg") {
let _ = window.set_background_color(Some(color));
}
}
/// Reads a `#rrggbb` theme token as an opaque colour for the window
/// background, so that no white frame shows before the page paints.
fn token_color(theme: &theme::Theme, name: &str) -> Option<Color> {