From 3e3f045d650a839d21f7b649da7aa5c19bd2e38b Mon Sep 17 00:00:00 2001 From: Aylur Date: Sun, 1 Sep 2024 14:17:36 +0200 Subject: monorepo structuring --- lib/battery/upower.vala | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 lib/battery/upower.vala (limited to 'lib/battery/upower.vala') diff --git a/lib/battery/upower.vala b/lib/battery/upower.vala new file mode 100644 index 0000000..9c18ffd --- /dev/null +++ b/lib/battery/upower.vala @@ -0,0 +1,58 @@ +namespace AstalBattery { +public class UPower : Object { + private IUPower proxy; + private HashTable _devices = + new HashTable(str_hash, str_equal); + + public List devices { + owned get { return _devices.get_values(); } + } + + public signal void device_added(Device device); + public signal void device_removed(Device device); + + public Device display_device { owned get { return Device.get_default(); }} + + public string daemon_version { owned get { return proxy.daemon_version; } } + public bool on_battery { get { return proxy.on_battery; } } + public bool lid_is_closed { get { return proxy.lid_is_closed; } } + public bool lis_is_present { get { return proxy.lid_is_closed; } } + + public string critical_action { + owned get { + try { + return proxy.get_critical_action(); + } catch (Error error) { + critical(error.message); + return ""; + } + } + } + + construct { + try { + proxy = Bus.get_proxy_sync( + BusType.SYSTEM, + "org.freedesktop.UPower", + "/org/freedesktop/UPower" + ); + + foreach (var path in proxy.enumerate_devices()) + _devices.set(path, new Device(path)); + + proxy.device_added.connect((path) => { + _devices.set(path, new Device(path)); + notify_property("devices"); + }); + + proxy.device_removed.connect((path) => { + device_removed(_devices.get(path)); + _devices.remove(path); + notify_property("devices"); + }); + } catch (Error error) { + critical(error.message); + } + } +} +} -- cgit v1.2.3