diff --git a/asusd/src/config.rs b/asusd/src/config.rs index 9515cfc4..842248b5 100644 --- a/asusd/src/config.rs +++ b/asusd/src/config.rs @@ -8,6 +8,12 @@ use serde::{Deserialize, Serialize}; const CONFIG_FILE: &str = "asusd.ron"; +/// Default value for base_charge_control_end_threshold when not present in config. +/// Returns 0 so restore_charge_limit() skips restoration for upgraded configs. +fn default_base_charge_limit() -> u8 { + 0 +} + #[derive(Default, Clone, Deserialize, Serialize, PartialEq)] pub struct Tuning { pub enabled: bool, @@ -19,8 +25,8 @@ type Tunings = HashMap; pub struct Config { // The current charge limit applied pub charge_control_end_threshold: u8, - /// Save charge limit for restoring - #[serde(skip)] + /// Save charge limit for restoring after one-shot full charge + #[serde(default = "default_base_charge_limit")] pub base_charge_control_end_threshold: u8, pub disable_nvidia_powerd_on_battery: bool, /// An optional command/script to run when power is changed to AC @@ -86,6 +92,9 @@ impl Default for Config { fn default() -> Self { Self { charge_control_end_threshold: 100, + // NOTE: This is intentionally 100 (not 0 like the serde default). + // New installs get 100 (no limit). Upgraded configs missing this + // field get 0 via serde, which skips restore_charge_limit(). base_charge_control_end_threshold: 100, disable_nvidia_powerd_on_battery: true, ac_command: Default::default(),