From 6c161a11cae2c8da092e566917b8553db220ffb5 Mon Sep 17 00:00:00 2001 From: Maxim Karasev Date: Sun, 29 Aug 2021 14:28:36 +0300 Subject: [PATCH] Reliably autodetect battery device in statusbar Wireless devices have "Wireless" type, so we search for nodes with type "Battery". We also may handle wireless devices that way, if anyone needs that. Signed-off-by: Stacy Harper --- scripts/core/sxmo_statusbar.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/core/sxmo_statusbar.sh b/scripts/core/sxmo_statusbar.sh index 3f3e797..f75a6f2 100755 --- a/scripts/core/sxmo_statusbar.sh +++ b/scripts/core/sxmo_statusbar.sh @@ -54,12 +54,14 @@ update() { fi fi - # Battery pct - BATTERY_DEVICE="${BATTERY_DEVICE:-"/sys/class/power_supply/axp20x-battery"}" - PCT="$(cat "$BATTERY_DEVICE"/capacity)" - BATSTATUS="$( - cut -c1 "$BATTERY_DEVICE"/status - )" + # Find battery and get percentage + status + for power_supply in /sys/class/power_supply/*; do + if [ "$(cat "$power_supply"/type)" = "Battery" ]; then + PCT="$(cat "$power_supply"/capacity)" + BATSTATUS="$(cut -c1 "$power_supply"/status)" + fi + done + if [ "$BATSTATUS" = "C" ]; then if [ "$PCT" -lt 20 ]; then BATSTATUS="$PCT% "