diff --git a/src/battery.rs b/src/battery.rs index f167ab0..4d05bbc 100644 --- a/src/battery.rs +++ b/src/battery.rs @@ -168,10 +168,7 @@ fn path_exists_and_writable(path: &Path) -> bool { } // Try to open the file with write access to verify write permission - match fs::OpenOptions::new().write(true).open(path) { - Ok(_) => true, - Err(_) => false, - } + fs::OpenOptions::new().write(true).open(path).is_ok() } /// Identifies if a battery supports threshold control and which pattern it uses diff --git a/src/config/load.rs b/src/config/load.rs index 9679dc0..663f72e 100644 --- a/src/config/load.rs +++ b/src/config/load.rs @@ -84,14 +84,17 @@ fn load_and_parse_config(path: &Path) -> Result { let mut charger_profile = toml_app_config.charger.clone(); let mut battery_profile = toml_app_config.battery.clone(); - // If profile-specific battery thresholds are not set, inherit from global config - if charger_profile.battery_charge_thresholds.is_none() { - charger_profile.battery_charge_thresholds = - toml_app_config.battery_charge_thresholds.clone(); - } + // Clone global battery_charge_thresholds once if it exists + if let Some(global_thresholds) = toml_app_config.battery_charge_thresholds { + // Apply to charger profile if not already set + if charger_profile.battery_charge_thresholds.is_none() { + charger_profile.battery_charge_thresholds = Some(global_thresholds.clone()); + } - if battery_profile.battery_charge_thresholds.is_none() { - battery_profile.battery_charge_thresholds = toml_app_config.battery_charge_thresholds; + // Apply to battery profile if not already set + if battery_profile.battery_charge_thresholds.is_none() { + battery_profile.battery_charge_thresholds = Some(global_thresholds); + } } // Convert AppConfigToml to AppConfig diff --git a/src/cpu.rs b/src/cpu.rs index fb35a9a..075e520 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -257,12 +257,10 @@ fn validate_epb_value(epb: &str) -> Result<()> { if let Ok(value) = epb.parse::() { if value <= 15 { return Ok(()); - } else { - return Err(ControlError::InvalidValueError(format!( - "EPB numeric value must be between 0 and 15, got {}", - value - ))); } + return Err(ControlError::InvalidValueError(format!( + "EPB numeric value must be between 0 and 15, got {value}" + ))); } // If not a number, check if it's a recognized string value diff --git a/src/main.rs b/src/main.rs index e5f6fba..de2cbcc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -396,7 +396,11 @@ fn main() { // Get available platform profiles and validate early if possible match cpu::get_platform_profiles() { Ok(available_profiles) => { - if !available_profiles.contains(&profile) { + if available_profiles.contains(&profile) { + info!("Setting platform profile to '{profile}'"); + cpu::set_platform_profile(&profile) + .map_err(|e| Box::new(e) as Box) + } else { error!( "Invalid platform profile: '{}'. Available profiles: {}", profile, @@ -407,10 +411,6 @@ fn main() { profile, available_profiles.join(", ") ))) as Box) - } else { - info!("Setting platform profile to '{}'", profile); - cpu::set_platform_profile(&profile) - .map_err(|e| Box::new(e) as Box) } } Err(_) => {