[gnome-shell/mcatanzaro/#2276] Fix prompt for updates on end session dialog



commit e94fc08f91aa21abf8511ae1596d563bef84f6eb
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Tue Mar 17 20:56:33 2020 -0500

    Fix prompt for updates on end session dialog
    
    Since PackageKit 1.11.1, the prompt to install updates on the end
    session dialog has been (mostly) broken. The problem is that it only
    works if PackageKit is running at the time the end session dialog is
    opened; otherwise, our GDBusProxy has invalidated all of its properties,
    which we read to see if update is possible. We need to autostart
    PackageKit before reading its properties to fix this problem. That would
    be easy if we were calling a method to see if an update or distro
    upgrade were available, but since we're just checking a property, using
    cached properties won't suffice. We'll have to manually check the
    property value to ensure we autostart PackageKit.
    
    Most of the code is written by Florian. Thanks Florian!
    
    Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/2276

 js/ui/endSessionDialog.js | 49 ++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 40 insertions(+), 9 deletions(-)
---
diff --git a/js/ui/endSessionDialog.js b/js/ui/endSessionDialog.js
index 42ae0d3f26..8d29435bc5 100644
--- a/js/ui/endSessionDialog.js
+++ b/js/ui/endSessionDialog.js
@@ -29,6 +29,8 @@ const UserWidget = imports.ui.userWidget;
 
 const { loadInterfaceXML } = imports.misc.fileUtils;
 
+Gio._promisify(Gio.DBusConnection.prototype, 'call', 'call_finish');
+
 const _ITEM_ICON_SIZE = 64;
 
 const EndSessionDialogIface = loadInterfaceXML('org.gnome.SessionManager.EndSessionDialog');
@@ -346,9 +348,9 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
 
         // Use a different description when we are installing a system upgrade
         // if the PackageKit proxy is available (i.e. PackageKit is available).
-        if (this._pkOfflineProxy && dialogContent.upgradeDescription) {
-            let name = this._pkOfflineProxy.PreparedUpgrade['name'].deep_unpack();
-            let version = this._pkOfflineProxy.PreparedUpgrade['version'].deep_unpack();
+        if (this._updateInfo && dialogContent.upgradeDescription) {
+            let name = this._updateInfo.PreparedUpgrade['name'].deep_unpack();
+            let version = this._updateInfo.PreparedUpgrade['version'].deep_unpack();
 
             if (name != null && version != null)
                 description = dialogContent.upgradeDescription(name, version);
@@ -608,16 +610,46 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
         });
     }
 
-    OpenAsync(parameters, invocation) {
+    async _getUpdateInfo() {
+        const connection = this._pkOfflineProxy.get_connection();
+        const reply = await connection.call(
+            this._pkOfflineProxy.g_name,
+            this._pkOfflineProxy.g_object_path,
+            'org.freedesktop.DBus.Properties',
+            'GetAll',
+            new GLib.Variant('(s)', [this._pkOfflineProxy.g_interface_name]),
+            null,
+            Gio.DBusCallFlags.NONE,
+            -1,
+            null);
+        const [info] = reply.recursiveUnpack();
+        return info;
+    }
+
+    async OpenAsync(parameters, invocation) {
         let [type, timestamp, totalSecondsToStayOpen, inhibitorObjectPaths] = parameters;
         this._totalSecondsToStayOpen = totalSecondsToStayOpen;
         this._type = type;
 
+        try {
+            this._updateInfo = await this._getUpdateInfo();
+        } catch (e) {
+            if (this._pkOfflineProxy !== null)
+                log('Failed to get update info from PackageKit: %s'.format(e.message));
+
+            this._updateInfo = {
+                UpdateTriggered: false,
+                UpdatePrepared: false,
+                UpgradeTriggered: false,
+                PreparedUpgrade: {},
+            };
+        }
+
         // Only consider updates and upgrades if PackageKit is available.
         if (this._pkOfflineProxy && this._type == DialogType.RESTART) {
-            if (this._pkOfflineProxy.UpdateTriggered)
+            if (this._updateInfo.UpdateTriggered)
                 this._type = DialogType.UPDATE_RESTART;
-            else if (this._pkOfflineProxy.UpgradeTriggered)
+            else if (this._updateInfo.UpgradeTriggered)
                 this._type = DialogType.UPGRADE_RESTART;
         }
 
@@ -646,9 +678,8 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
         if (dialogContent.showOtherSessions)
             this._loadSessions();
 
-        // Only consider updates and upgrades if PackageKit is available.
-        let updateTriggered = this._pkOfflineProxy ? this._pkOfflineProxy.UpdateTriggered : false;
-        let updatePrepared = this._pkOfflineProxy ? this._pkOfflineProxy.UpdatePrepared : false;
+        let updateTriggered = this._updateInfo.UpdateTriggered;
+        let updatePrepared = this._updateInfo.UpdatePrepared;
         let updatesAllowed = this._updatesPermission && this._updatesPermission.allowed;
 
         _setCheckBoxLabel(this._checkBox, dialogContent.checkBoxText || '');


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]