From aa063c20fdae661cd12f5cbe3e58b6ef2f1df051 Mon Sep 17 00:00:00 2001 From: bitr8 Date: Mon, 5 Jan 2026 17:22:54 +1100 Subject: [PATCH] fix: persist base_charge_control_end_threshold for one-shot charging base_charge_control_end_threshold was marked #[serde(skip)] so it only lived in memory. triggering one-shot charge then restarting asusd would permanently lose the original charge limit. - remove #[serde(skip)] so the field gets persisted - add serde default of 0 for backwards compat (skips restore for upgraded configs missing the field) - add comments explaining Default vs serde default asymmetry --- asusd/src/config.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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(),