From 1fdf25d8b3eeca3f463653df9c26cdfba5874210 Mon Sep 17 00:00:00 2001 From: eightscrow <183341520+eightscrow@users.noreply.github.com> Date: Tue, 28 Apr 2026 15:19:25 +0300 Subject: [PATCH] Fix battery detection for non-BAT power supply names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Apple Silicon (Asahi Linux), the battery shows up as macsmc-battery instead of BAT0. All battery scripts assumed BAT* naming, so the Ctrl+Alt+Super+B hotkey showed nothing and the low battery monitor never activated. Fixed omarchy-battery-present to check all power supply entries — the existing type check already filters out AC adapters. Fixed the four upower scripts to grep for /battery_ prefix which upower uses for all batteries regardless of kernel device name. Fixed the migration script to use omarchy-battery-present so the timer activates on fresh Asahi installs too. --- bin/omarchy-battery-capacity | 2 +- bin/omarchy-battery-present | 2 +- bin/omarchy-battery-remaining | 2 +- bin/omarchy-battery-remaining-time | 2 +- bin/omarchy-battery-status | 2 +- migrations/1752168292.sh | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bin/omarchy-battery-capacity b/bin/omarchy-battery-capacity index fa4b4c03db..6a41ec38aa 100755 --- a/bin/omarchy-battery-capacity +++ b/bin/omarchy-battery-capacity @@ -3,7 +3,7 @@ # Returns the battery full capacity in Wh (rounded to whole number). # Used by omarchy-battery-status for displaying battery capacity. -battery_info=$(upower -i $(upower -e | grep BAT)) +battery_info=$(upower -i $(upower -e | grep '/battery_' | head -1)) echo "$battery_info" | awk '/energy-full:/ { printf "%d", $2 diff --git a/bin/omarchy-battery-present b/bin/omarchy-battery-present index 2b052a7aeb..60d042c89d 100755 --- a/bin/omarchy-battery-present +++ b/bin/omarchy-battery-present @@ -3,7 +3,7 @@ # Returns true if a battery is present on the system. # Used by the battery monitor and other battery-related checks. -for bat in /sys/class/power_supply/BAT*; do +for bat in /sys/class/power_supply/*; do [[ -r $bat/present ]] && [[ $(cat $bat/present) == "1" ]] && [[ $(cat $bat/type) == "Battery" ]] && diff --git a/bin/omarchy-battery-remaining b/bin/omarchy-battery-remaining index 26ea718fd1..d637bb06f4 100755 --- a/bin/omarchy-battery-remaining +++ b/bin/omarchy-battery-remaining @@ -3,7 +3,7 @@ # Returns the battery percentage remaining as an integer. # Used by the battery monitor and the Ctrl + Shift + Super + B hotkey. -upower -i $(upower -e | grep BAT) | awk '/percentage/ { +upower -i $(upower -e | grep '/battery_' | head -1) | awk '/percentage/ { print int($2) exit }' diff --git a/bin/omarchy-battery-remaining-time b/bin/omarchy-battery-remaining-time index c4f39593a6..19dc755585 100755 --- a/bin/omarchy-battery-remaining-time +++ b/bin/omarchy-battery-remaining-time @@ -2,7 +2,7 @@ # Returns the battery time remaining (to empty or full) in a compact format. -battery_info=$(upower -i $(upower -e | grep BAT)) +battery_info=$(upower -i $(upower -e | grep '/battery_' | head -1)) echo "$battery_info" | awk '/time to (empty|full)/ { value = $4 diff --git a/bin/omarchy-battery-status b/bin/omarchy-battery-status index 021c0aa498..7437b0034d 100755 --- a/bin/omarchy-battery-status +++ b/bin/omarchy-battery-status @@ -3,7 +3,7 @@ # Returns a formatted battery status string with percentage and power draw/charge. # Used by the battery notification hotkey (Ctrl + Shift + Super + B). -battery_info=$(upower -i $(upower -e | grep BAT)) +battery_info=$(upower -i $(upower -e | grep '/battery_' | head -1)) percentage=$(echo "$battery_info" | awk '/percentage/ { print int($2) diff --git a/migrations/1752168292.sh b/migrations/1752168292.sh index 0f529134ca..947c35ea1c 100644 --- a/migrations/1752168292.sh +++ b/migrations/1752168292.sh @@ -1,6 +1,6 @@ echo "Enable battery low notifications for laptops" -if ls /sys/class/power_supply/BAT* &>/dev/null && [[ ! -f ~/.local/share/omarchy/config/systemd/user/omarchy-battery-monitor.service ]]; then +if omarchy-battery-present && [[ ! -f ~/.local/share/omarchy/config/systemd/user/omarchy-battery-monitor.service ]]; then mkdir -p ~/.config/systemd/user cp ~/.local/share/omarchy/config/systemd/user/omarchy-battery-monitor.* ~/.config/systemd/user/