DesignCraft: An open-source page and layout design editor written by scratch in pure Rust
Reload ICC profiles loaded in Color Settings at start-up
NetterSilver55f9e690e341
diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rsindex 40787954f..b35acabcb 100644--- a/crates/ui-egui/src/dialogs.rs+++ b/crates/ui-egui/src/dialogs.rs@@ -2456,6 +2456,9 @@ pub fn show(app: &mut DesignApp, ctx: &egui::Context) {{match app.session.execute("color.loadProfile", &json!({"path": path})) {Ok(_) => {+ if !app.ui.color_profiles.contains(&path) {+ app.ui.color_profiles.push(path);+ }let f = app.session.execute("color.settings", &json!({})).unwrap_or_default();d.fields.insert("profiles".into(), f["profiles"].clone());}diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rsindex 535c87629..59d0d6354 100644--- a/crates/ui-egui/src/lib.rs+++ b/crates/ui-egui/src/lib.rs@@ -223,6 +223,9 @@ pub struct UiState {pub pages_panel: panels::pages::PanelOptions,/// Edit › Color Settings (re-applied at start).pub color_settings: Option<designcraft_color::cms::ColorSettings>,+ /// ICC files loaded with Edit › Color Settings › Load Profile… (loaded again at start, before+ /// `color_settings`, so a loaded working space stays chosen).+ pub color_profiles: Vec<String>,/// View › Proof Colors and View › Proof Setup.pub proof_colors: bool,pub proof_setup: designcraft_color::cms::ProofSetup,@@ -383,6 +386,7 @@ impl Default for UiState {pages_parents_height: None,pages_panel: Default::default(),color_settings: None,+ color_profiles: Vec::new(),proof_colors: false,proof_setup: Default::default(),dynamic_spelling: false,@@ -1106,8 +1110,22 @@ impl DesignApp {self.window_maximized = ctx.input(|i| i.viewport().maximized.unwrap_or(false));if !self.color_applied {self.color_applied = true;+ for path in self.ui.color_profiles.clone() {+ if let Err(e) = self.session.execute("color.loadProfile", &json!({"path": path})) {+ log::warn!("Color Settings: {e}");+ self.status_error("Color Settings", e);+ }+ }if let Some(cs) = self.ui.color_settings.clone() {- let _ = designcraft_color::cms::set_active(&cs.with_known_profiles());+ let known = cs.with_known_profiles();+ for (saved, used) in [(&cs.rgb, &known.rgb), (&cs.cmyk, &known.cmyk)] {+ if saved != used {+ let e = format!("saved profile {saved} is not available; using {used}");+ log::warn!("Color Settings: {e}");+ self.status_error("Color Settings", e);+ }+ }+ let _ = designcraft_color::cms::set_active(&known);}}let scale = self.ui.ui_scale.clamp(0.5, 3.0);diff --git a/crates/ui-egui/tests/it/color_profiles_restart.rs b/crates/ui-egui/tests/it/color_profiles_restart.rsnew file mode 100644index 000000000..ad7ebcc75--- /dev/null+++ b/crates/ui-egui/tests/it/color_profiles_restart.rs@@ -0,0 +1,43 @@+//! A working space loaded with Edit › Color Settings › Load Profile… is active again after a+//! restart (#1474). Colour settings are process-wide, so this lives in the integration tests.++use designcraft_color::cms::{self, ColorSettings};+use designcraft_engine::Session;+use designcraft_ui_egui::{DesignApp, Services, UiState};+use serde_json::json;++/// The app's first frame, where saved settings are applied.+fn start(app: &mut DesignApp) {+ let mut out = egui::Context::default().run_ui(egui::RawInput::default(), |ui| app.logic(&ui.ctx().clone()));+ out.textures_delta.clear();+}++#[test]+fn loaded_working_space_survives_restart() {+ let dir = tempfile::tempdir().unwrap();+ let path = dir.path().join("restart-test.icc");+ let mut profile = cms::icc_out::generic_cmyk_profile().unwrap().clone();+ profile.description = "Restart Test CMYK".into();+ std::fs::write(&path, profile.with_encoded_bytes().to_bytes().as_slice()).unwrap();++ // What ui.json holds after Load Profile… and choosing that profile in a previous session.+ let chosen = ColorSettings { cmyk: "Restart Test CMYK".into(), ..Default::default() };+ let saved = json!({"colorProfiles": [path.to_string_lossy()], "colorSettings": chosen});++ // This process has never loaded the profile: only the built-in ones are known.+ assert!(!cms::profiles().iter().any(|p| p.name == chosen.cmyk));+ let mut app = DesignApp::new(Session::new(), Services::default());+ app.ui = serde_json::from_value::<UiState>(saved).unwrap();+ start(&mut app);+ let active = cms::active_settings();+ cms::set_active(&ColorSettings::default()).unwrap();+ assert_eq!(active, chosen, "the loaded working space is active again");++ // A saved profile that can't be loaded any more is reported, not silently replaced.+ let gone = json!({"colorProfiles": [dir.path().join("gone.icc").to_string_lossy()], "colorSettings": ColorSettings { cmyk: "Gone CMYK".into(), ..Default::default() }});+ let mut app = DesignApp::new(Session::new(), Services::default());+ app.ui = serde_json::from_value::<UiState>(gone).unwrap();+ start(&mut app);+ assert_eq!(cms::active_settings(), ColorSettings::default());+ assert!(app.ui.status.contains("Gone CMYK"), "{}", app.ui.status);+}diff --git a/crates/ui-egui/tests/it/main.rs b/crates/ui-egui/tests/it/main.rsindex 2d07c9629..6950fc776 100644--- a/crates/ui-egui/tests/it/main.rs+++ b/crates/ui-egui/tests/it/main.rs@@ -1,2 +1,4 @@#[cfg(not(target_arch = "wasm32"))]+mod color_profiles_restart;+#[cfg(not(target_arch = "wasm32"))]mod native_job_lifetime_control;