diff --git a/asusd/src/aura_laptop/config.rs b/asusd/src/aura_laptop/config.rs index 218c597d..24e32b8f 100644 --- a/asusd/src/aura_laptop/config.rs +++ b/asusd/src/aura_laptop/config.rs @@ -33,7 +33,6 @@ pub struct AuraConfig { } impl StdConfig for AuraConfig { - /// Detect the keyboard type and load from default DB if data available fn new() -> Self { panic!("This should not be used"); } diff --git a/asusd/src/aura_laptop/trait_impls.rs b/asusd/src/aura_laptop/trait_impls.rs index db10d166..8a4daa66 100644 --- a/asusd/src/aura_laptop/trait_impls.rs +++ b/asusd/src/aura_laptop/trait_impls.rs @@ -182,7 +182,6 @@ impl AuraZbus { self.0.set_brightness(config.brightness.into()).await?; config.set_builtin(effect); config.write(); - Ok(()) } @@ -208,9 +207,10 @@ impl AuraZbus { let mut config = self.0.config.lock().await; for opt in options.states { let zone = opt.zone; - for config in config.enabled.states.iter_mut() { - if config.zone == zone { - *config = opt; + for state in config.enabled.states.iter_mut() { + if state.zone == zone { + *state = opt; + break; } } } diff --git a/asusd/src/aura_types.rs b/asusd/src/aura_types.rs index 3a8cf12d..e1621c9c 100644 --- a/asusd/src/aura_types.rs +++ b/asusd/src/aura_types.rs @@ -196,6 +196,7 @@ impl DeviceHandle { Some(Arc::new(Mutex::new(k))) }); + // Load saved mode, colours, brightness, power from disk; apply on reload let mut config = AuraConfig::load_and_update_config(prod_id); config.led_type = aura_type; let aura = Aura { diff --git a/rog-control-center/src/ui/setup_aura.rs b/rog-control-center/src/ui/setup_aura.rs index 5ef41040..f8b9577c 100644 --- a/rog-control-center/src/ui/setup_aura.rs +++ b/rog-control-center/src/ui/setup_aura.rs @@ -83,15 +83,6 @@ pub fn setup_aura_page( set_ui_props_async!(handle, aura, AuraPageData, led_power); set_ui_props_async!(handle, aura, AuraPageData, device_type); - if let Ok(data) = aura.led_mode_data().await { - let d = data.into(); - handle - .upgrade_in_event_loop(move |h| { - h.global::().invoke_update_led_mode_data(d); - }) - .ok(); - } - let modes_vec: Vec = match prefetched_supported { Some(p) => p, None => aura @@ -101,11 +92,15 @@ pub fn setup_aura_page( .map(|m| m.iter().map(|n| (*n).into()).collect()) .unwrap_or_default(), }; - let current_mode: Option = aura.led_mode().await.ok().map(|m| m.into()); + // Restore saved mode, colours, zone, speed, direction from asusd (persisted to disk). + // Use effect.mode as single source — avoid led_mode() which can fail (try_lock). + let restore = aura.led_mode_data().await.ok(); + let raw_mode: Option = restore.as_ref().map(|d| d.mode.into()); + let d_slint = restore.map(|d| d.into()); handle - .upgrade_in_event_loop(move |handle| { - let names = handle.global::().get_mode_names(); + .upgrade_in_event_loop(move |h| { + let names = h.global::().get_mode_names(); let mut raws = Vec::new(); let mut mode_names = Vec::new(); for (i, name) in names.iter().enumerate() { @@ -115,17 +110,17 @@ pub fn setup_aura_page( mode_names.push(name.clone()); } } - handle - .global::() + h.global::() .set_supported_basic_modes(raws.as_slice().into()); - handle - .global::() + h.global::() .set_available_mode_names(mode_names.as_slice().into()); - if let Some(cm) = current_mode { - let idx = raws.iter().position(|&r| r == cm).unwrap_or(0) as i32; - handle - .global::() - .set_current_available_mode(idx); + if let Some(d) = d_slint { + h.global::().invoke_update_led_mode_data(d); + if let Some(cm) = raw_mode { + let idx = raws.iter().position(|&r| r == cm).unwrap_or(0) as i32; + h.global::().set_current_available_mode(idx); + } + h.invoke_external_colour_change(); } }) .map_err(|e| error!("{e}"))