diff --git a/src/app/mod.rs b/src/app/mod.rs index e6b9a116..45926639 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -3777,6 +3777,28 @@ impl OpenCADStudio { fn boot_web() -> (Self, Task) { #[cfg_attr(target_arch = "wasm32", allow(unused_mut))] let mut s = Self::new(); + + // CMMS embedding (not upstream): follow the CMMS user's light/dark + // theme. window.CAD_EDITOR_CONFIG.dark is set by cad-edit.php from + // theme_is_dark(). Overrides the persisted config theme that + // Self::new()'s apply_config() just set - the embedded editor always + // opens straight into a file and should match the CMMS chrome, not + // whatever theme was last picked in a standalone session. Standalone + // use (no config) leaves everything untouched. + if let Some(cfg) = crate::sys::cmms_config() { + let iced_theme = if cfg.dark { + iced::Theme::Oxocarbon + } else { + iced::Theme::Light + }; + s.ui_theme = config::UiThemeConfig { + name: iced_theme.to_string(), + palette: config::UiThemePalette::from_iced(iced_theme.seed()), + }; + s.active_theme = iced_theme; + s.theme_color_inputs = s.ui_theme.palette.hex_values(); + } + let focus = s.focus_cmd_input(); let primary_font = crate::scene::text::web_font::preload_language( &crate::i18n::active_language_tag(), diff --git a/src/sys.rs b/src/sys.rs index c9ada909..4357f2e3 100644 --- a/src/sys.rs +++ b/src/sys.rs @@ -320,6 +320,10 @@ pub struct CmmsConfig { pub load_url: Option, pub attachment_id: Option, pub original_name: Option, + // Whether the CMMS user's active theme reads as dark (theme_is_dark() in + // cad-edit.php). Drives the editor's iced theme at boot so it opens + // light or dark to match. Absent (standalone) -> false -> unchanged. + pub dark: bool, } #[cfg(target_arch = "wasm32")] @@ -336,6 +340,12 @@ pub fn cmms_config() -> Option { .ok()? .as_string() }; + let get_bool = |key: &str| -> bool { + js_sys::Reflect::get(&config, &JsValue::from_str(key)) + .ok() + .and_then(|v| v.as_bool()) + .unwrap_or(false) + }; Some(CmmsConfig { save_url: get_str("saveUrl")?, job_id: get_str("jobId")?, @@ -343,6 +353,7 @@ pub fn cmms_config() -> Option { load_url: get_str("loadUrl"), attachment_id: get_str("attachmentId"), original_name: get_str("originalName"), + dark: get_bool("dark"), }) }