summaryrefslogtreecommitdiff
path: root/src/on_ac_power
diff options
context:
space:
mode:
authorVictor Lowther <victor.lowther@gmail.com>2010-06-22 19:09:40 -0500
committerVictor Lowther <victor.lowther@gmail.com>2010-06-22 19:09:40 -0500
commit87883a1cc89618b5a985a9c78f8234fc1570c54c (patch)
tree921154d47c47576de76d5c50e7c3f31caa78d352 /src/on_ac_power
parent0326034188bfd6943c4958775b7b18e701c3c0ca (diff)
Make on_ac_power check sysfs directly.
This avoids us depending on power managers that depend on us.
Diffstat (limited to 'src/on_ac_power')
-rwxr-xr-xsrc/on_ac_power43
1 files changed, 11 insertions, 32 deletions
diff --git a/src/on_ac_power b/src/on_ac_power
index 1f9c59e..b0aa105 100755
--- a/src/on_ac_power
+++ b/src/on_ac_power
@@ -30,38 +30,17 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# prefer UPower if available
-if s="$(dbus-send --system --print-reply \
- --dest=org.freedesktop.UPower \
- /org/freedesktop/UPower \
- org.freedesktop.DBus.Properties.Get \
- string:org.freedesktop.UPower string:OnBattery)"; then
- echo "$s" | grep -q 'boolean false'
- exit $?
-fi
+# If we do not have any power supplies, assume we are on AC
+ret=0
-# try its old name 'DeviceKit-power' too
-if s="$(dbus-send --system --print-reply \
- --dest=org.freedesktop.DeviceKit.Power \
- /org/freedesktop/DeviceKit/Power \
- org.freedesktop.DBus.Properties.Get \
- string:org.freedesktop.DeviceKit.Power string:OnBattery)"; then
- echo "$s" | grep -q 'boolean false'
- exit $?
-fi
-
-# Check for AC/DC/etc adapters
-ac_adapters="$(hal-find-by-capability --capability ac_adapter)"
-
-# If there are no AC adapters, it is most likely a desktop.
-# Assume online, since we have no data.
-[ -z "$ac_adapters" ] && exit 0
-
-# If any of them are online, then we're done.
-for device in $ac_adapters ; do
- present="$(hal-get-property --udi "$device" --key ac_adapter.present)"
- [ "$present" = "true" ] && exit 0
+# Iterate through power supplies sysfs knows about.
+for ps in /sys/class/power_supply/*; do
+ [ -r "$ps/online" ] || continue
+ # OK, we know we have an AC adaptor.
+ # Our default return changes to failed.
+ ret=1
+ read -r ps_status < "$ps/online"
+ [ 1 -eq "$ps_status" ] && exit 0
done
-# If there are adapters, but none are online, we're not on AC.
-exit 1
+exit "$ret"