From c2b842f10c29ea536c91942b220817cd14f38001 Mon Sep 17 00:00:00 2001 From: jastincheis Date: Sun, 6 Sep 2026 18:25:41 +0300 Subject: [PATCH] Fix stale charge-limit threshold in battery status panel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit omarchy-battery-status preferred UPower's charge-*-threshold over the device's own sysfs value. The macsmc-battery driver never calls power_supply_changed() for a threshold-only write, so UPower's copy goes stale the moment battery-charge-limit changes it and never catches up — the panel kept showing the old limit (e.g. 80%) even after the slider set a new one (e.g. 87%), even though the real hardware threshold was applied correctly. Panel.qml already worked around this same staleness for the slider's own display by reading the CLI instead of UPower; apply the same fix here by reading sysfs first and falling back to UPower only when sysfs isn't readable. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Nyix3VJYzz9JEXHPwHPYTK --- bin/omarchy-battery-status | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/bin/omarchy-battery-status b/bin/omarchy-battery-status index e4ccceac04f..808ea2df72e 100755 --- a/bin/omarchy-battery-status +++ b/bin/omarchy-battery-status @@ -73,13 +73,18 @@ power_rate=$(awk -v rate="${power_rate_raw:-0}" 'BEGIN { print rounded }') state=$(awk '/state/ { print $2; exit }' <<<"$battery_info") -threshold_start=$(awk '/charge-start-threshold:/ { gsub(/%/, "", $2); print int($2); exit }' <<<"$battery_info") -threshold_end=$(awk '/charge-end-threshold:/ { gsub(/%/, "", $2); print int($2); exit }' <<<"$battery_info") # The device's own sysfs directory first -- native-path names it, whatever it -# is called -- and only then the BAT* guess, which never matches macsmc-battery. -[[ -z $threshold_end ]] && threshold_end=$(cat "$battery_path"/charge_control_end_threshold 2>/dev/null | head -1) -[[ -z $threshold_start ]] && threshold_start=$(cat "$battery_path"/charge_control_start_threshold 2>/dev/null | head -1) +# is called. UPower's charge-*-threshold is only a fallback: the +# macsmc-battery driver never calls power_supply_changed() for a +# threshold-only write, so UPower's copy goes stale the moment +# battery-charge-limit changes it and never catches up (Panel.qml hits the +# same staleness for the slider and reads the CLI directly for that reason). +# The BAT* guess never matches macsmc-battery either way. +threshold_end=$(cat "$battery_path"/charge_control_end_threshold 2>/dev/null | head -1) +threshold_start=$(cat "$battery_path"/charge_control_start_threshold 2>/dev/null | head -1) +[[ -z $threshold_end ]] && threshold_end=$(awk '/charge-end-threshold:/ { gsub(/%/, "", $2); print int($2); exit }' <<<"$battery_info") +[[ -z $threshold_start ]] && threshold_start=$(awk '/charge-start-threshold:/ { gsub(/%/, "", $2); print int($2); exit }' <<<"$battery_info") [[ -z $threshold_end ]] && threshold_end=$(cat "$power_supply_path"/BAT*/charge_control_end_threshold 2>/dev/null | head -1) [[ -z $threshold_start ]] && threshold_start=$(cat "$power_supply_path"/BAT*/charge_control_start_threshold 2>/dev/null | head -1)