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

@ -0,0 +1,102 @@
//! Theme commands: `theme.list` and `theme.systemPreference`. Switching
//! themes goes through `settings.set appearance.theme`; whenever the
//! resolved theme changes, `themeChanged` carries its tokens.
use serde::Deserialize;
use serde_json::{Value, json};
use crate::cmd::params::parse;
use crate::theme::{self, BUILTIN, Theme};
use crate::{Command, CommandSpec, EngineError, Event, Outcome, State};
/// The setting that selects the theme.
pub const SETTING: &str = "appearance.theme";
/// The theme the current settings and OS preference resolve to.
pub fn resolved(state: &State) -> Theme {
let setting = state.settings.get(SETTING);
let id = setting
.as_ref()
.and_then(Value::as_str)
.unwrap_or(theme::SYSTEM);
theme::resolve(id, state.system_dark)
}
/// The `themeChanged` event for a theme.
pub fn changed_event(theme: &Theme) -> Event {
Event::ThemeChanged {
id: theme.id.to_string(),
dark: theme.dark,
tokens: theme::token_map(theme),
}
}
/// Emits `themeChanged` if the resolved theme is no longer `before`.
pub fn emit_if_changed(state: &mut State, before: Theme) {
let now = resolved(state);
if now != before {
state.emit(changed_event(&now));
}
}
/// `theme.list`: the built-in themes.
pub struct List;
impl Command for List {
fn spec(&self) -> &CommandSpec {
&CommandSpec {
id: "theme.list",
label: "List Themes",
menu_path: None,
default_shortcut: None,
params: "none; returns [{ id, label, dark }], label is a message-catalog key",
}
}
fn run(&self, _state: &mut State, _params: Value) -> Result<Outcome, EngineError> {
let list: Vec<_> = BUILTIN
.iter()
.map(|t| json!({ "id": t.id, "label": t.label_key, "dark": t.dark }))
.collect();
Ok(Outcome::value(Value::Array(list)))
}
}
/// Params of `theme.systemPreference`.
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct PreferenceParams {
/// Whether the OS prefers a dark theme.
dark: bool,
}
/// `theme.systemPreference`: the frontend reports the OS colour preference;
/// in "system" mode a change of it switches the theme.
pub struct SystemPreference;
impl Command for SystemPreference {
fn spec(&self) -> &CommandSpec {
&CommandSpec {
id: "theme.systemPreference",
label: "Report System Theme",
menu_path: None,
default_shortcut: None,
params: "{ dark: bool }; returns the resolved theme { id, dark, tokens }; emits themeChanged when it changes",
}
}
fn run(&self, state: &mut State, params: Value) -> Result<Outcome, EngineError> {
let p: PreferenceParams = parse(self.spec().id, params)?;
let before = resolved(state);
state.system_dark = Some(p.dark);
emit_if_changed(state, before);
let now = resolved(state);
let value = serde_json::to_value(changed_event(&now))
.map_err(|e| EngineError::Internal(e.to_string()))?;
let Value::Object(mut fields) = value else {
return Err(EngineError::Internal("theme is not an object".into()));
};
fields.remove("kind");
Ok(Outcome::value(Value::Object(fields)))
}
}