fix(power): #60 name-agnostic system-battery scan
All checks were successful
Check / eval (push) Successful in 2m53s

Replace BAT* globs with type=Battery + !scope=Device (same filter as
nomarchy-battery-notify) in charge-limit oneshot, menu gates, Waybar
power-profile self-gate, doctor, and install chassis detection. CMB0-
style names get charge-cap and laptop modules consistently.

V3 pending: confirm on non-BAT* hardware (HARDWARE-QUEUE). Close #60.

Verified: V1 (option-docs, hardware-db-modules, battery-charge-limit VM).
This commit is contained in:
Bernardo Magri
2026-07-10 08:32:24 +01:00
parent 09388196a9
commit c962d07841
9 changed files with 80 additions and 29 deletions

View File

@@ -174,6 +174,28 @@ let
# icon set (Papirus) via rofi's per-row icon protocol see row() below.
# `nomarchy-menu` with no argument shows the module picker.
# System batteries: type=Battery, not scope=Device same filter as
# nomarchy-battery-notify. Name-agnostic (BAT0, CMB0, test_battery)
# so charge-limit / power-profile gates match notify (BACKLOG #60).
has_system_battery() {
local d
for d in /sys/class/power_supply/*/; do
[ "$(cat "$d/type" 2>/dev/null)" = Battery ] || continue
[ "$(cat "$d/scope" 2>/dev/null || echo System)" = Device ] && continue
return 0
done
return 1
}
has_charge_threshold() {
local d
for d in /sys/class/power_supply/*/; do
[ "$(cat "$d/type" 2>/dev/null)" = Battery ] || continue
[ "$(cat "$d/scope" 2>/dev/null || echo System)" = Device ] && continue
[ -e "$d/charge_control_end_threshold" ] && return 0
done
return 1
}
urlencode() {
local s="$1" out="" ch i
for ((i = 0; i < ''${#s}; i++)); do
@@ -264,9 +286,8 @@ let
# rows drive powerprofilesctl like the power-profile picker, charge
# rows drive the same theme-sync writer as batterylimit. Each half
# self-gates on its hardware, so a desktop with neither just toasts.
bats=(/sys/class/power_supply/BAT*)
haveppd=false; command -v powerprofilesctl >/dev/null 2>&1 && haveppd=true
havecharge=false; [ -e "''${bats[0]}/charge_control_end_threshold" ] && havecharge=true
havecharge=false; has_charge_threshold && havecharge=true
if ! $haveppd && ! $havecharge; then
notify-send "Power" "No power-profile or charge-limit control on this machine."
exit 0
@@ -755,7 +776,6 @@ ${themeRows}
# System submenu connectivity and machine state. Snapshots and the
# power-profile picker self-gate (BTRFS+snapper / laptop on ppd), so
# the submenu shrinks to match the hardware, like the Waybar modules.
bats=(/sys/class/power_supply/BAT*)
choice=$( {
row "Network${menuHint "network"}" network-wireless
row "VPN" network-vpn
@@ -783,13 +803,12 @@ ${themeRows}
# on VMs/headless via services.fwupd.enable=false), like Printers.
command -v fwupdmgr >/dev/null 2>&1 && row "Firmware" firmware-manager
command -v nomarchy-control-center >/dev/null 2>&1 && row "Control Center" preferences-desktop
if [ -e "''${bats[0]}" ] && command -v powerprofilesctl >/dev/null 2>&1; then
if has_system_battery && command -v powerprofilesctl >/dev/null 2>&1; then
row "Power profile" preferences-system-power
fi
# Self-gated on the charge-threshold sysfs node (laptops that
# expose it), like Power profile above.
[ -e "''${bats[0]}/charge_control_end_threshold" ] \
&& row "Battery limit" battery-080
has_charge_threshold && row "Battery limit" battery-080
back
} | rofi -dmenu -show-icons -markup-rows -p System) || exit 0
case "$choice" in
@@ -820,8 +839,7 @@ ${themeRows}
# it lands on the next sys-rebuild the sysfs oneshot in power.nix
# owns applying it (boot + AC-replug). Self-gated in System; guard
# here too in case it's invoked directly.
bats=(/sys/class/power_supply/BAT*)
[ -e "''${bats[0]}/charge_control_end_threshold" ] \
has_charge_threshold \
|| { notify-send "Battery limit" "No charge-threshold control on this machine."; exit 0; }
cur=$(nomarchy-theme-sync get settings.power.batteryChargeLimit 2>/dev/null)
sel=$( {