pop-os/cosmic-settings

[Enhancement] Battery device level reporting when fully charged - consistency between applets & settings.

Opened this issue · 0 comments

In continuation to the fix of #561 , from analysis of what gnome does here:

Gnome-shell's implementation here: https://github.com/GNOME/gnome-shell/blob/d60bdc95faf3607ec579558074cf1ca919db041a/js/ui/status/system.js#L19-L85

const BUS_NAME = 'org.freedesktop.UPower';
const OBJECT_PATH = '/org/freedesktop/UPower/devices/DisplayDevice';

 // The icons
        let chargingState = this._proxy.State === UPower.DeviceState.CHARGING
            ? '-charging' : '';
        let fillLevel = 10 * Math.floor(this._proxy.Percentage / 10);
        const charged =
            this._proxy.State === UPower.DeviceState.FULLY_CHARGED ||
            (this._proxy.State === UPower.DeviceState.CHARGING && fillLevel === 100);
        const icon = charged
            ? 'battery-level-100-charged-symbolic'
            : `battery-level-${fillLevel}${chargingState}-symbolic`;

we should add an additional check for DeviceState.FULLY_CHARGED to not render any time to empty / time to full. & also render the thunder icon:

 const charged =
            this._proxy.State === UPower.DeviceState.FULLY_CHARGED ||
            (this._proxy.State === UPower.DeviceState.CHARGING && fillLevel === 100);
        const icon = charged
            ? 'battery-level-100-charged-symbolic'

i can see that we do not have a battery-level-100-charged-symbolic' but essentially it would be the equivalent of the -charging- one in our case. Here is a screenshot of the existing icons:

Screenshot 2024-11-01 at 6 45 07 PM Screenshot 2024-11-01 at 6 46 22 PM

Note: Checking that the battery-level == 100 to denote that it is fully-charged is a valid way to go from what i understand from this original implementation:
https://gitlab.freedesktop.org/upower/upower/-/blob/master/src/linux/up-device-idevice.c?ref_type=heads#L285-294

/* get charging status */
	node = plist_dict_get_item (dict, "BatteryIsCharging");
	if (!node) {
		plist_free(dict);
		goto out;
	}
	plist_get_bool_val (node, &charging);

	if (percentage == 100)
		state = UP_DEVICE_STATE_FULLY_CHARGED;
	else if (percentage == 0)
		state = UP_DEVICE_STATE_EMPTY;
	else if (charging)
		state = UP_DEVICE_STATE_CHARGING;
	else
		state = UP_DEVICE_STATE_DISCHARGING; /* upower doesn't have a "not charging" state */

Somebody with a laptop that could test this thoroughly should pick this up.