gnome-shell-batime-extended/batime@martin.zurowietz.de/power.js
Mershl 4f6250ee1b Add handling for PENDING_CHARGE state
Based on testing the state is reached when
the hardware's charge limit blocks further
charging.

GNOME displays the state as "Not Charging"
in the power options and the quick settings.
The used icon is the default, non-charging
battery.

Currently batime shows PENDING_CHARGE as
"Estimating..." which suggests a temporary
state. Without external change
the state is permanent (based on my testing).
2022-02-22 17:45:12 +01:00

42 lines
1.3 KiB
JavaScript

const { GObject} = imports.gi;
const UPower = imports.gi.UPowerGlib;
const BaseIndicator = imports.ui.status.power.Indicator;
var Indicator = GObject.registerClass(
class Indicator extends BaseIndicator {
// Adapted from _getStatus of the parent.
_getTime() {
let seconds = 0;
if (this._proxy.State === UPower.DeviceState.FULLY_CHARGED) {
return '';
} else if (this._proxy.State === UPower.DeviceState.CHARGING) {
seconds = this._proxy.TimeToFull;
} else if (this._proxy.State === UPower.DeviceState.DISCHARGING) {
seconds = this._proxy.TimeToEmpty;
} else if (this._proxy.State === UPower.DeviceState.PENDING_CHARGE) {
return '';
} else {
// state is PENDING_DISCHARGE or UNKNOWN
return _('Estimating…');
}
let time = Math.round(seconds / 60);
if (time === 0) {
// 0 is reported when UPower does not have enough data
// to estimate battery life
return _('Estimating…');
}
let minutes = time % 60;
let hours = Math.floor(time / 60);
// Translators: this is <hours>:<minutes>
return _('%d\u2236%02d').format(hours, minutes);
}
_sync() {
super._sync();
this._percentageLabel.text = this._getTime();
}
});