[gnome-shell/mcatanzaro/#2717: 41/41] endSessionDialog: default to not installing updates on low battery
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell/mcatanzaro/#2717: 41/41] endSessionDialog: default to not installing updates on low battery
- Date: Mon, 10 Aug 2020 21:35:52 +0000 (UTC)
commit 5d4636dde3382fc20a2d4a8b2592ea87f94c60c6
Author: Michael Catanzaro <mcatanzaro gnome org>
Date: Fri Jul 24 19:08:16 2020 -0500
endSessionDialog: default to not installing updates on low battery
If the user's battery power is low, we should not check the checkbox to
install updates by default. Rationale: if the user's battery is not low,
it's very unlikely to run out during a normal system upgrade. Low
battery is defined as any level below 30%, matching our battery status
indicator.
We'll also change the battery warning to only display when battery is
actually low. However, we will still always warn on battery for full
system upgrades, since these are expected to take a long time.
Future improvement: it would be nice to make the checkbox insensitive
when on low power. However, I don't think we currently have a proper
style for insensitive checkboxes. I was unable to make it look good.
Lastly, note that I did not test this on a laptop. I tested this by
mocking the return values of _isDischargingBattery() and
_isBatteryLow().
Fixes https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2717
js/ui/endSessionDialog.js | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)
---
diff --git a/js/ui/endSessionDialog.js b/js/ui/endSessionDialog.js
index 00dd9b220e..9cb88203ca 100644
--- a/js/ui/endSessionDialog.js
+++ b/js/ui/endSessionDialog.js
@@ -18,7 +18,7 @@
*/
const { AccountsService, Clutter, Gio,
- GLib, GObject, Pango, Polkit, Shell, St } = imports.gi;
+ GLib, GObject, Pango, Polkit, Shell, St, UPowerGlib: UPower } = imports.gi;
const CheckBox = imports.ui.checkBox;
const Dialog = imports.ui.dialog;
@@ -31,6 +31,8 @@ const { loadInterfaceXML } = imports.misc.fileUtils;
const _ITEM_ICON_SIZE = 64;
+const LOW_BATTERY_THRESHOLD = 30;
+
const EndSessionDialogIface = loadInterfaceXML('org.gnome.SessionManager.EndSessionDialog');
const logoutDialogContent = {
@@ -157,7 +159,7 @@ const LogindSession = Gio.DBusProxy.makeProxyWrapper(LogindSessionIface);
const PkOfflineIface = loadInterfaceXML('org.freedesktop.PackageKit.Offline');
const PkOfflineProxy = Gio.DBusProxy.makeProxyWrapper(PkOfflineIface);
-const UPowerIface = loadInterfaceXML('org.freedesktop.UPower');
+const UPowerIface = loadInterfaceXML('org.freedesktop.UPower.Device');
const UPowerProxy = Gio.DBusProxy.makeProxyWrapper(UPowerIface);
function findAppFromInhibitor(inhibitor) {
@@ -244,7 +246,7 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
this._powerProxy = new UPowerProxy(Gio.DBus.system,
'org.freedesktop.UPower',
- '/org/freedesktop/UPower',
+ '/org/freedesktop/UPower/devices/DisplayDevice',
(proxy, error) => {
if (error) {
log(error.message);
@@ -279,7 +281,7 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
this._batteryWarning = new St.Label({
style_class: 'end-session-dialog-battery-warning',
- text: _('Running on battery power: Please plug in before installing updates.'),
+ text: _('Low battery power: please plug in before installing updates.'),
});
this._batteryWarning.clutter_text.ellipsize = Pango.EllipsizeMode.NONE;
this._batteryWarning.clutter_text.line_wrap = true;
@@ -329,6 +331,16 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
this._user.disconnect(this._userChangedId);
}
+ _isDischargingBattery() {
+ return this._powerProxy.IsPresent &&
+ this._powerProxy.State !== UPower.DeviceState.CHARGING &&
+ this._powerProxy.State !== UPower.DeviceState.FULLY_CHARGED;
+ }
+
+ _isBatteryLow() {
+ return this._isDischargingBattery() && this._powerProxy.Percentage < LOW_BATTERY_THRESHOLD;
+ }
+
_sync() {
let open = this.state == ModalDialog.State.OPENING || this.state == ModalDialog.State.OPENED;
if (!open)
@@ -342,10 +354,9 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
if (dialogContent.subjectWithUpdates && this._checkBox.checked)
subject = dialogContent.subjectWithUpdates;
- if (dialogContent.showBatteryWarning) {
- this._batteryWarning.visible =
- this._powerProxy.OnBattery && this._checkBox.checked;
- }
+ // Hide battery warning if the user has plugged in.
+ if (this._batteryWarning.visible)
+ this._batteryWarning.visible = this._isDischargingBattery();
let description;
let displayTime = _roundSecondsToInterval(this._totalSecondsToStayOpen,
@@ -754,13 +765,18 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
_setCheckBoxLabel(this._checkBox, dialogContent.checkBoxText || '');
this._checkBox.visible = dialogContent.checkBoxText && updatePrepared && updatesAllowed;
- this._checkBox.checked = this._checkBox.visible;
+
+ if (this._type === DialogType.UPGRADE_RESTART)
+ this._checkBox.checked = this._checkBox.visible && updateTriggered &&
!this._isDischargingBattery();
+ else
+ this._checkBox.checked = this._checkBox.visible && !this._isBatteryLow();
// We show the warning either together with the checkbox, or when
// updates have already been triggered, but the user doesn't have
// enough permissions to cancel them.
this._batteryWarning.visible = dialogContent.showBatteryWarning &&
- (this._checkBox.visible || updatePrepared && updateTriggered &&
!updatesAllowed);
+ this._isBatteryLow() &&
+ (this._checkBox.visible || updatePrepared && updateTriggered && !updatesAllowed);
this._updateButtons();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]