diff options
author | Ojas Kavathe <[email protected]> | 2024-11-27 15:24:57 +0530 |
---|---|---|
committer | Ojas Kavathe <[email protected]> | 2024-11-27 15:24:57 +0530 |
commit | 95b2daac6cd4867ead5fb84defa6673410421039 (patch) | |
tree | 60f970015afe9270c983a89e653a630838c27a00 /lib | |
parent | 358044bdfd357916bad9ae9298fd89b54291a7a6 (diff) |
bluetooth: percentage notify on change
Diffstat (limited to 'lib')
-rw-r--r-- | lib/bluetooth/bluetooth.vala | 2 | ||||
-rw-r--r-- | lib/bluetooth/device.vala | 22 |
2 files changed, 19 insertions, 5 deletions
diff --git a/lib/bluetooth/bluetooth.vala b/lib/bluetooth/bluetooth.vala index 68431e5..02005c3 100644 --- a/lib/bluetooth/bluetooth.vala +++ b/lib/bluetooth/bluetooth.vala @@ -170,7 +170,7 @@ public class AstalBluetooth.Bluetooth : Object { var battery = new Battery((IBattery)iface); var device = _devices.lookup(iface.g_object_path); if (device != null) { - device.battery = battery; + device.set_battery(battery); } sync(); } diff --git a/lib/bluetooth/device.vala b/lib/bluetooth/device.vala index e4df528..74f8d83 100644 --- a/lib/bluetooth/device.vala +++ b/lib/bluetooth/device.vala @@ -3,7 +3,7 @@ */ public class AstalBluetooth.Device : Object { private IDevice proxy; - public Battery battery; + private Battery battery; internal ObjectPath object_path { owned get; private set; } @@ -21,6 +21,15 @@ public class AstalBluetooth.Device : Object { }); } + internal void set_battery(Battery battery) { + this.battery = battery; + + notify_property("battery_percentage"); + battery.notify["percentage"].connect((obj, pspec) => { + notify_property("battery_percentage"); + }); + } + /** * List of 128-bit UUIDs that represents the available remote services. */ @@ -105,10 +114,14 @@ public class AstalBluetooth.Device : Object { } /** - * The percentage of battery left as an unsigned 8-bit integer. + * The percentage of battery left on the device if it has one, else 0. */ - public uint battery_percentage { get { return battery.percentage; } } - + public uint battery_percentage { + get { + if (battery != null) return battery.percentage; + else return 0; + } + } /** * The name alias for the remote device. @@ -144,6 +157,7 @@ public class AstalBluetooth.Device : Object { yield proxy.disconnect(); } + /** * This method connects a specific profile of this device. * The UUID provided is the remote service UUID for the profile. |