fix(power): #60 name-agnostic system-battery scan
All checks were successful
Check / eval (push) Successful in 2m53s
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:
@@ -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=$( {
|
||||
|
||||
@@ -60,7 +60,14 @@ let
|
||||
'';
|
||||
|
||||
powerProfileStatus = pkgs.writeShellScriptBin "nomarchy-powerprofile-status" ''
|
||||
case "$(ls /sys/class/power_supply/ 2>/dev/null)" in *BAT*) ;; *) exit 0 ;; esac
|
||||
# Name-agnostic system battery (BAT0, CMB0, …) — BACKLOG #60.
|
||||
has_bat=
|
||||
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
|
||||
has_bat=1; break
|
||||
done
|
||||
[ -n "$has_bat" ] || exit 0
|
||||
command -v powerprofilesctl >/dev/null 2>&1 || exit 0
|
||||
prof=$(powerprofilesctl get 2>/dev/null) || exit 0
|
||||
case "$prof" in
|
||||
|
||||
@@ -106,8 +106,9 @@
|
||||
example = 80;
|
||||
description = ''
|
||||
Stop charging at this percentage to extend battery lifespan,
|
||||
where the hardware exposes a charge threshold
|
||||
(/sys/class/power_supply/BAT*/charge_control_end_threshold).
|
||||
where the hardware exposes charge_control_end_threshold on a
|
||||
system battery (type=Battery under /sys/class/power_supply;
|
||||
name-agnostic — BAT0, CMB0, …).
|
||||
null leaves charging at the firmware default. Backend-independent
|
||||
(a small systemd unit writes the sysfs knob, re-applied on AC
|
||||
state changes), so it works under PPD too; needs
|
||||
|
||||
@@ -50,7 +50,12 @@ in
|
||||
RemainAfterExit = true;
|
||||
};
|
||||
script = ''
|
||||
for thresh in /sys/class/power_supply/BAT*/charge_control_end_threshold; do
|
||||
# Name-agnostic (BAT0, CMB0, …): same type/scope filter as
|
||||
# nomarchy-battery-notify — BACKLOG #60.
|
||||
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
|
||||
thresh="$d/charge_control_end_threshold"
|
||||
[ -w "$thresh" ] && echo ${toString cfg.batteryChargeLimit} > "$thresh"
|
||||
done
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user