CMMS embedding: follow the CMMS light/dark theme
CAD_EDITOR_CONFIG.dark (set by cad-edit.php from theme_is_dark()) -> CmmsConfig.dark (src/sys.rs). boot_web() (src/app/mod.rs) overrides the persisted active_theme/ui_theme with iced::Theme::Light or ::Oxocarbon so the embedded editor opens to match the CMMS chrome. Standalone use keeps its own persisted theme.
This commit is contained in:
parent
6b07760943
commit
5c42f88f23
2 changed files with 33 additions and 0 deletions
|
|
@ -3777,6 +3777,28 @@ impl OpenCADStudio {
|
||||||
fn boot_web() -> (Self, Task<Message>) {
|
fn boot_web() -> (Self, Task<Message>) {
|
||||||
#[cfg_attr(target_arch = "wasm32", allow(unused_mut))]
|
#[cfg_attr(target_arch = "wasm32", allow(unused_mut))]
|
||||||
let mut s = Self::new();
|
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 focus = s.focus_cmd_input();
|
||||||
let primary_font = crate::scene::text::web_font::preload_language(
|
let primary_font = crate::scene::text::web_font::preload_language(
|
||||||
&crate::i18n::active_language_tag(),
|
&crate::i18n::active_language_tag(),
|
||||||
|
|
|
||||||
11
src/sys.rs
11
src/sys.rs
|
|
@ -320,6 +320,10 @@ pub struct CmmsConfig {
|
||||||
pub load_url: Option<String>,
|
pub load_url: Option<String>,
|
||||||
pub attachment_id: Option<String>,
|
pub attachment_id: Option<String>,
|
||||||
pub original_name: Option<String>,
|
pub original_name: Option<String>,
|
||||||
|
// 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")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
|
@ -336,6 +340,12 @@ pub fn cmms_config() -> Option<CmmsConfig> {
|
||||||
.ok()?
|
.ok()?
|
||||||
.as_string()
|
.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 {
|
Some(CmmsConfig {
|
||||||
save_url: get_str("saveUrl")?,
|
save_url: get_str("saveUrl")?,
|
||||||
job_id: get_str("jobId")?,
|
job_id: get_str("jobId")?,
|
||||||
|
|
@ -343,6 +353,7 @@ pub fn cmms_config() -> Option<CmmsConfig> {
|
||||||
load_url: get_str("loadUrl"),
|
load_url: get_str("loadUrl"),
|
||||||
attachment_id: get_str("attachmentId"),
|
attachment_id: get_str("attachmentId"),
|
||||||
original_name: get_str("originalName"),
|
original_name: get_str("originalName"),
|
||||||
|
dark: get_bool("dark"),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue