Refresh the charge icon immediately on charger plug/unplug
This commit is contained in:
1 parent
6a6222c198
commit
eaf08abcd4
9 files changed
+159
-6
No files matched your search
@@ -1,5 +1,11 @@
|
||||
# Bananarchy battery/charger statusbar hook (U4).
|
||||
# Only the two PM8916 supplies exist on these devices; filtering avoids
|
||||
# spawning a shell for unrelated power_supply change events.
|
||||
# Only the PM8916 supplies exist on these devices; filtering avoids spawning a
|
||||
# shell for unrelated power_supply change events.
|
||||
SUBSYSTEM=="power_supply", ACTION=="change", KERNEL=="pm8916-bms-vm", RUN+="/bin/sh -c 'DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/10000 /usr/share/sxmo/default_hooks/sxmo_hook_battery.sh udev >/dev/null 2>&1 &'"
|
||||
SUBSYSTEM=="power_supply", ACTION=="change", KERNEL=="pm8916-lbc-chgr", RUN+="/bin/sh -c 'DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/10000 /usr/share/sxmo/default_hooks/sxmo_hook_battery.sh udev >/dev/null 2>&1 &'"
|
||||
# A VBUS plug/unplug changes the charger's online attribute, not necessarily
|
||||
# the reported capacity. Force the charge icon immediately and re-read sysfs
|
||||
# after the short race window so the icon actually changes at that moment.
|
||||
SUBSYSTEM=="power_supply", ACTION=="change", KERNEL=="pm8916-lbc-chgr", RUN+="/bin/sh -c 'DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/10000 /usr/bin/bananarchy-battery-charge-event.sh >/dev/null 2>&1 &'"
|
||||
# Some PM8916 firmware revisions publish the VBUS transition on a separate
|
||||
# USB/Mains supply instead of the charger node.
|
||||
SUBSYSTEM=="power_supply", ACTION=="change", ENV{POWER_SUPPLY_ONLINE}=="0|1", KERNEL!="pm8916-bms-vm", RUN+="/bin/sh -c 'DISPLAY=:0 XDG_RUNTIME_DIR=/run/user/10000 /usr/bin/bananarchy-battery-charge-event.sh >/dev/null 2>&1 &'"
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/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
|
||||
Reference in new issue
Block a user