fix: do not write unavailable settings to the config file

This commit is contained in:
Denis Benato
2026-01-18 15:38:41 +01:00
parent 72ef6dea07
commit d541581012

View File

@@ -459,8 +459,18 @@ impl CtrlPlatform {
#[zbus(signal_context)] ctxt: SignalEmitter<'_>, #[zbus(signal_context)] ctxt: SignalEmitter<'_>,
policy: PlatformProfile, policy: PlatformProfile,
) -> Result<(), FdoErr> { ) -> Result<(), FdoErr> {
self.config.lock().await.platform_profile_on_battery = policy; // If the requested profile isn't available on this platform, and it's
self.set_platform_profile(ctxt, policy).await?; // `Quiet`, fall back to `LowPower` so we don't write an unavailable
// profile into the config file.
let mut chosen = policy;
if let Ok(choices) = self.platform.get_platform_profile_choices() {
if chosen == PlatformProfile::Quiet && !choices.contains(&PlatformProfile::Quiet) {
chosen = PlatformProfile::LowPower;
}
}
self.config.lock().await.platform_profile_on_battery = chosen;
self.set_platform_profile(ctxt, chosen).await?;
self.config.lock().await.write(); self.config.lock().await.write();
Ok(()) Ok(())
} }
@@ -488,8 +498,16 @@ impl CtrlPlatform {
#[zbus(signal_context)] ctxt: SignalEmitter<'_>, #[zbus(signal_context)] ctxt: SignalEmitter<'_>,
policy: PlatformProfile, policy: PlatformProfile,
) -> Result<(), FdoErr> { ) -> Result<(), FdoErr> {
self.config.lock().await.platform_profile_on_ac = policy; // Mirror the same fallback behavior for AC profile changes.
self.set_platform_profile(ctxt, policy).await?; let mut chosen = policy;
if let Ok(choices) = self.platform.get_platform_profile_choices() {
if chosen == PlatformProfile::Quiet && !choices.contains(&PlatformProfile::Quiet) {
chosen = PlatformProfile::LowPower;
}
}
self.config.lock().await.platform_profile_on_ac = chosen;
self.set_platform_profile(ctxt, chosen).await?;
self.config.lock().await.write(); self.config.lock().await.write();
Ok(()) Ok(())
} }