Skip to content

Commit

Permalink
bluetooth: percentage notify on change
Browse files Browse the repository at this point in the history
  • Loading branch information
ojaskavathe committed Nov 27, 2024
1 parent 358044b commit 95b2daa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/bluetooth/bluetooth.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
22 changes: 18 additions & 4 deletions lib/bluetooth/device.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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.
*/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 95b2daa

Please sign in to comment.