Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
db5e690
Warn about a low battery at 20% as well as 10%
itxkarthik Nov 26, 2026
ba0a904
Send the 10% warning after the 20% one's hooks finish
itxkarthik Nov 26, 2026
a814b4b
Make low-battery warnings persistent and audible
kairosci Nov 26, 2026
f858ffc
Dismiss low-battery warning after recovery
kairosci Nov 26, 2026
49ea389
Handle low-battery dismissal edge cases
kairosci Nov 26, 2026
25ed413
Keep battery alerts transient across shell restarts
kairosci Nov 26, 2026
caaa2bb
Retry battery warning after an active send
kairosci Nov 30, 2026
5267c4f
Pin upower locale and parse all time units in omarchy-battery-status
shuruheel Nov 28, 2026
287ad92
Show the Surface Pro 11's battery cycle count from the Surface EC
turbineBMW Nov 27, 2026
cdb1c98
Announce when the charger is connected
emrgim Nov 29, 2026
3655060
Keep the charger toast across a short reconnect
emrgim Nov 29, 2026
417cccd
Wait for a battery event after a failed charge-limit write
Cynnamoroll Nov 30, 2026
7730413
Wait for charge-limit events in the regression test
Cynnamoroll Nov 30, 2026
51da86d
Report the charger's rating and the power drawn from it in battery st…
jvdp11 Nov 30, 2026
aeae6ca
Show the charger and how its power is shared in the power panel
jvdp11 Nov 30, 2026
713b17a
Take the charger split's direction from the battery state, and keep t…
jvdp11 Nov 30, 2026
44691f9
Refresh power-panel battery telemetry less often
Cynnamoroll Dec 1, 2026
9ac8c7f
Keep one low-battery latch and let the usage tests compile beside it.
chessing234 Dec 1, 2026
55451e7
Serialize low battery warnings and recovery dismissal
chessing234 Dec 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/omarchy-battery-low
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ fi

level=$1

omarchy-notification-send -g 󱐋 -u normal "$(omarchy-i18n battery.lowTitle)" "$(omarchy-i18n battery.lowBody "$level")" -i battery-caution -t 30000
omarchy-notification-send --transient -g 󱐋 -u critical "$(omarchy-i18n battery.lowTitle)" "$(omarchy-i18n battery.lowBody "$level")" -i battery-caution
Comment thread
chessing234 marked this conversation as resolved.
Resolved
omarchy-hook battery-low "$level"
8 changes: 8 additions & 0 deletions bin/omarchy-battery-low-dismiss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

# omarchy:summary=Dismiss the resolved low-battery warning
# omarchy:hidden=true

set -euo pipefail

omarchy-notification-dismiss "$(omarchy-i18n battery.lowTitle)"
16 changes: 16 additions & 0 deletions bin/omarchy-battery-plugged
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

# omarchy:summary=Announce that the charger was just connected.
# omarchy:hidden=true

set -euo pipefail

# Nerd Font power plug. The icon theme is tried first; this is the fallback.
glyph=$'\U000f06a5'
status=$(omarchy-battery-status || true)

if [[ -n $status ]]; then
omarchy-notification-send -g "$glyph" -u normal "$(omarchy-i18n battery.chargerConnectedTitle)" "$status" -i ac-adapter --transient
else
omarchy-notification-send -g "$glyph" -u normal "$(omarchy-i18n battery.chargerConnectedTitle)" "$(omarchy-i18n battery.chargerConnectedBody)" -i ac-adapter --transient
fi
55 changes: 52 additions & 3 deletions bin/omarchy-battery-status
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

shell_output=false
power_supply_path="${OMARCHY_POWER_SUPPLY_PATH:-/sys/class/power_supply}"
hwmon_path="${OMARCHY_HWMON_PATH:-/sys/class/hwmon}"
sleep_run_dir="${OMARCHY_SLEEP_RUN_DIR:-/run/omarchy}"
battery_state_dir="${OMARCHY_BATTERY_STATE_DIR:-${XDG_STATE_HOME:-$HOME/.local/state}/omarchy/battery}"
surface_battery_dir="${OMARCHY_SURFACE_BATTERY_DIR:-/run/surface-pro-11-battery}"

case "${1:-}" in
"")
Expand Down Expand Up @@ -45,13 +47,13 @@ battery=""
battery_info=""
while read -r candidate; do
[[ -n $candidate ]] || continue
candidate_info=$(upower -i "$candidate" 2>/dev/null) || continue
candidate_info=$(LC_ALL=C upower -i "$candidate" 2>/dev/null) || continue
if grep -qE '^\s*power supply:\s+yes' <<<"$candidate_info"; then
battery=$candidate
battery_info=$candidate_info
break
fi
done < <(upower -e 2>/dev/null | grep '/battery_')
done < <(LC_ALL=C upower -e 2>/dev/null | grep '/battery_')
[[ -z $battery ]] && exit 0

percentage=$(awk '/percentage/ { print int($2); exit }' <<<"$battery_info")
Expand All @@ -60,7 +62,13 @@ energy=$(awk '/^ *energy:/ { print $2; exit }' <<<"$battery_info")
energy_full=$(awk '/energy-full:/ { print $2; exit }' <<<"$battery_info")
energy_full_design=$(awk '/energy-full-design:/ { print $2; exit }' <<<"$battery_info")
upower_capacity=$(awk '/^ *capacity:/ { gsub(/%/, "", $2); print $2; exit }' <<<"$battery_info")
upower_hours=$(awk '/time to (empty|full)/ { print ($5 ~ /^minute/ ? $4 / 60 : $4); exit }' <<<"$battery_info")
upower_hours=$(awk '/time to (empty|full)/ {
if ($5 ~ /^second/) printf "%.17g", $4 / 3600
else if ($5 ~ /^minute/) printf "%.17g", $4 / 60
else if ($5 ~ /^day/) printf "%.17g", $4 * 24
else print $4
exit
}' <<<"$battery_info")
power_rate_raw=$(awk '/energy-rate/ { print $2; exit }' <<<"$battery_info")
native_path=$(awk '/native-path/ { print $2; exit }' <<<"$battery_info")
battery_path="$power_supply_path/$native_path"
Expand Down Expand Up @@ -218,6 +226,12 @@ if [[ $shell_output == "true" ]]; then
cycles=""
[[ ! -r $battery_path/cycle_count ]] || cycles=$(<"$battery_path/cycle_count")
[[ -n $cycles ]] || cycles=$(cat "$power_supply_path"/BAT*/cycle_count 2>/dev/null | head -1)
# The Surface Pro 11's battery manager firmware keeps no count and reads 0;
# the Surface EC has it, and microsoft-surface-pro-11-support writes it here.
if [[ -z $cycles || $cycles == "0" ]]; then
surface_cycles=$(read_sysfs_number "$surface_battery_dir/cycle-count" || true)
[[ -z $surface_cycles ]] || cycles=$surface_cycles
fi

[[ -n $cycles ]] && printf 'cycles\t%s\n' "$cycles"

Expand All @@ -229,6 +243,41 @@ if [[ $shell_output == "true" ]]; then
fi
fi

# The connected charger: what it can give, and what is drawn from it now. A
# small charger under load leaves little for the battery, and the panel shows
# that split instead of a charge rate that looks like a fault. Apple Silicon
# reports the rating as input_power_limit on its Mains supply; USB-PD supplies
# elsewhere (UCSI) report the negotiated voltage_max and current_max. Below
# 5W is a plain USB port, not a charger rating.
charger_uw=0
for supply in "$power_supply_path"/*; do
[[ -r $supply/type && $(<"$supply/type") =~ ^(Mains|USB) ]] || continue
[[ $(read_sysfs_number "$supply/online" || true) == "1" ]] || continue
if supply_uw=$(read_sysfs_number "$supply/input_power_limit"); then
:
elif microvolts=$(read_sysfs_number "$supply/voltage_max") && microamps=$(read_sysfs_number "$supply/current_max"); then
supply_uw=$(( microvolts * microamps / 1000000 ))
else
continue
fi
if (( supply_uw > charger_uw )); then
charger_uw=$supply_uw
fi
done

if (( charger_uw >= 5000000 )); then
printf 'charger\t%sW\n' "$(( (charger_uw + 500000) / 1000000 ))"

# Only a sensor gives the draw itself (the Apple SMC's "AC Input Power");
# without one the panel shows the rating alone.
for label in "$hwmon_path"/*/power*_label; do
[[ -r $label && $(<"$label") == "AC Input Power" ]] || continue
microwatts=$(read_sysfs_number "${label%_label}_input") || continue
printf 'charger_draw\t%sW\n' "$(awk -v microwatts="$microwatts" 'BEGIN { rounded = sprintf("%.1f", microwatts / 1000000); sub(/\.0$/, "", rounded); print rounded }')"
break
done
fi

# Charge limit control metadata for the power panel.
limit_supported=0
if [[ $upower_threshold_supported == "yes" || -r $battery_path/charge_control_end_threshold ]]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# This hook is called with the current battery percentage when the low battery
# notification is sent. To put it into use, remove .sample from this file name.
# notification is sent.

SOUND_FILE="/usr/share/sounds/freedesktop/stereo/dialog-warning.oga"

Expand Down
2 changes: 2 additions & 0 deletions default/i18n/en/cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
"audio.micOn": "Microphone on",
"audio.noDevices": "No audio devices found",
"audio.noMicrophone": "No microphone found",
"battery.chargerConnectedBody": "Now charging",
"battery.chargerConnectedTitle": "Charger connected",
"battery.durationHours": "%1h",
"battery.durationHoursMinutes": "%1h %2m",
"battery.durationMinutes": "%1m",
Expand Down
7 changes: 7 additions & 0 deletions default/i18n/en/shell.json
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,13 @@
"power.chargeLimit": "Charge limit",
"power.chargeLimitFailed": "Could not update charge limit",
"power.chargeLimitTo": "Charge to only %1",
"power.charger": "CHARGER",
"power.chargerFromBattery": "From battery",
"power.chargerMaxed": "The charger is at its limit: a stronger one would charge faster",
"power.chargerShort": "The charger can't keep up: the battery covers the rest",
"power.chargerToBattery": "To battery",
"power.chargerToSystem": "To system",
"power.chargerUse": "%1 of %2",
"power.charging": "Charging",
"power.chargingPhrase1": "Pumping power",
"power.chargingPhrase2": "Injecting electrons",
Expand Down
3 changes: 2 additions & 1 deletion docs/notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ The `notifications` IPC target also answers `ping` (used by `omarchy-notificatio

Everything goes through the same sender contract, so the pieces are small:

- **Low battery** — `omarchy-battery-low` sends a normal toast that expires after 30 seconds (paused, like any card, while the deck is open) and runs the `battery-low` hook. Not critical: a critical toast never expires and comes back on every shell start, so the warning would outlive the charger going in. As an `omarchy-action` toast it still gets through Do Not Disturb.
- **Low battery** — `omarchy-battery-low` sends a critical, transient warning at 20% and again at 10%, and runs the `battery-low` hook. Each warning remains until dismissed or until charging starts or the battery recovers above 20%; recovery waits for any active sender to finish before dismissing its card. Transient warnings are not restored from notification history after a shell restart; the battery service rechecks the current reading and warns again if needed. The warning gets through Do Not Disturb.
- **Charger connected** — when line power arrives after the machine has been on battery, `omarchy-battery-plugged` sends a normal transient toast. A flip shorter than two seconds is ignored, so a USB-C renegotiation or a UPower reading that settles at startup does not announce a charger that was not just plugged in. A confirmation already earned survives a reconnect inside that window, and is dropped only if the machine stays on battery through it.
- **Crash capture** — `omarchy-crash-watch` follows the systemd-coredump
journal stream and announces each crashed program (deduped per minute) as a
critical toast whose click runs `omarchy-agent-crash` (via `--exec`, so a
Expand Down
16 changes: 16 additions & 0 deletions migrations/1795704847.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
echo "Enable the default sound for low-battery warnings"

default_hook="$OMARCHY_PATH/config/omarchy/hooks/battery-low.d/play-warning-sound"
user_hook="$HOME/.config/omarchy/hooks/battery-low.d/play-warning-sound"

if [[ -e $user_hook || -L $user_hook ]]; then
exit 0
fi

[[ -f $default_hook ]] || {
echo "Waiting for omarchy-settings to provide: $default_hook" >&2
exit 75
}

mkdir -p "$(dirname "$user_hook")"
cp -- "$default_hook" "$user_hook"
50 changes: 49 additions & 1 deletion shell/plugins/panels/power/Model.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,52 @@ function usageChart(hours, nowSeconds) {
return { columns: columns, screen: screen, used: used }
}

// How the charger's power is shared out. Battery status reports the charger's
// rating ("140W") and, where a sensor gives it, the power drawn from it now
// ("136.9W"), with the battery's state and rate. The battery's state, not the
// plug, gives the direction: a charger too weak for the load leaves the battery
// draining while plugged in. Charging, the rate flows into the battery and the
// rest of the draw is what the system takes; draining, the whole draw goes to
// the system and the battery covers the rest (drain). Fractions are of the
// rating. maxed: the charger gives all it has while the battery gets a small
// share of it or none. Null without a charger rating.
function chargerFlow(batteryInfo) {
var info = batteryInfo || {}
var limit = parseFloat(info.charger)
if (!(limit > 0)) return null

var rate = Math.max(0, parseFloat(info.rate) || 0)
var charging = info.state === "charging"
var draining = info.state === "discharging"
var draw = parseFloat(info.charger_draw)
var hasDraw = draw >= 0
var battery = charging ? rate : 0
if (hasDraw) battery = Math.min(battery, draw)
var system = hasDraw ? Math.max(0, draw - battery) : -1

function fraction(watts) { return Math.max(0, Math.min(1, watts / limit)) }

return {
limit: limit,
draw: hasDraw ? draw : -1,
battery: battery,
drain: draining ? rate : 0,
system: system,
batteryFraction: fraction(battery),
systemFraction: hasDraw ? fraction(system) : 0,
maxed: hasDraw && (charging || draining) && draw >= limit * 0.93 && battery < limit * 0.3
}
}

// A wattage in the shape battery status writes one, for localizeReading:
// whole watts from 10W up, one decimal below that.
function wattsReading(watts) {
var value = Math.max(0, Number(watts) || 0)
if (value >= 10) return Math.round(value) + "W"
var rounded = String(Math.round(value * 10) / 10)
return rounded + "W"
}

if (typeof module !== "undefined") {
module.exports = {
clampIndex: clampIndex,
Expand All @@ -241,6 +287,8 @@ if (typeof module !== "undefined") {
formatSleepTooltip: formatSleepTooltip,
isLowS0ix: isLowS0ix,
moveFocus: moveFocus,
usageChart: usageChart
usageChart: usageChart,
chargerFlow: chargerFlow,
wattsReading: wattsReading
}
}
Loading