38 lines
1.2 KiB
Bash
Executable File
38 lines
1.2 KiB
Bash
Executable File
#!/bin/sh
|
|
# Immediate charge-icon refresh on a USB/VBUS plug or unplug uevent.
|
|
#
|
|
# The battery hook's cache skips an unchanged state:percentage pair, and the
|
|
# charger's "online" / battery "status" sysfs attributes can still contain the
|
|
# old value when the uevent is delivered. A plain `sxmo_hook_battery.sh udev`
|
|
# therefore leaves the status bar icon unchanged at exactly the moment the
|
|
# user plugs or unplugs the cable. Force the icon once immediately, then
|
|
# re-read sysfs after a short delay. The lock coalesces the burst of uevents
|
|
# that the PM8916 charger emits for a single plug/unplug.
|
|
set -u
|
|
|
|
HOOK="${BANANARCHY_BATTERY_HOOK:-/usr/share/sxmo/default_hooks/sxmo_hook_battery.sh}"
|
|
LOCK="${BANANARCHY_BATTERY_LOCK:-/run/bananarchy-battery-charge.lock}"
|
|
DELAY="${BANANARCHY_BATTERY_RECHECK_DELAY:-2}"
|
|
|
|
export DISPLAY="${DISPLAY:-:0}"
|
|
export XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/10000}"
|
|
export HOME="${HOME:-/home/user}"
|
|
export SXMO_WM="${SXMO_WM:-dwm}"
|
|
export SXMO_STATUS_NAME="${SXMO_STATUS_NAME:-default}"
|
|
|
|
force_refresh() {
|
|
"$HOOK" force >/dev/null 2>&1 || true
|
|
}
|
|
|
|
force_refresh
|
|
|
|
exec 9>"$LOCK" 2>/dev/null || exit 0
|
|
if ! flock -n 9 2>/dev/null; then
|
|
exit 0
|
|
fi
|
|
(
|
|
sleep "$DELAY" 2>/dev/null || true
|
|
force_refresh
|
|
) >/dev/null 2>&1 &
|
|
exit 0
|