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



commit 1d39d9c7f427cf19f33e2dba311cf33532d9dca1
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,
    there's not really an obvious non-hackish way to do it. So I came up
    with this yucky hack: we can ping PackageKit, which will autostart it,
    then wait for it to update its properties. (The properties are not
    updated before we receive the reply to its ping.)
    
    The timeout is created to ensure that we don't fail to show the dialog
    if PackageKit responds to the ping but fails to update its properties in
    a reasonable amount of time. It's yucky, but we should be robust to that
    possibility.
    
    Fixes https://gitlab.gnome.org/GNOME/gnome-shell/issues/2276

 js/ui/endSessionDialog.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 55 insertions(+), 1 deletion(-)
---
diff --git a/js/ui/endSessionDialog.js b/js/ui/endSessionDialog.js
index 42ae0d3f26..d336101b94 100644
--- a/js/ui/endSessionDialog.js
+++ b/js/ui/endSessionDialog.js
@@ -608,11 +608,65 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
         });
     }
 
-    OpenAsync(parameters, invocation) {
+    _ensurePkOfflineProperties() {
+        return new Promise((resolve, reject) => {
+            // If PackageKit is not installed, or if it is running, we're done.
+            if (this._pkOfflineProxy == null || this._pkOfflineProxy.g_name_owner != null) {
+                resolve();
+                return;
+            }
+
+            // PackageKit is installed, but not running. We need to launch it
+            // before we can safely examine the properties of our D-Bus proxy. A
+            // simple ping will do. The 200ms timeout is arbitrary.
+            const pkLaunchTimeout = 200;
+            let timeoutID = 0;
+
+            let conn = this._pkOfflineProxy.get_connection();
+            conn.call('org.freedesktop.PackageKit',
+                '/org/freedesktop/PackageKit',
+                'org.freedesktop.DBus.Peer',
+                'Ping',
+                null, null, Gio.DBusCallFlags.NONE,
+                pkLaunchTimeout, null,
+                (source, res) => {
+                      try {
+                          conn.call_finish(res);
+
+                          let propertiesChangedID = 0;
+                          let timeoutID = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
+                              pkLaunchTimeout,
+                              () => {
+                                  this._pkOfflineProxy.disconnect(propertiesChangedID);
+                                  reject(new Error('Timed out waiting for PackageKit daemon'));
+                                  return GLib.SOURCE_REMOVE;
+                              });
+
+                          propertiesChangedID = this._pkOfflineProxy.connect(
+                              'g-properties-changed',
+                              (unusedChanged, unusedInvalidated) => {
+                                  this._pkOfflineProxy.disconnect(propertiesChangedID);
+                                  GLib.Source.remove(timeoutID);
+                                  resolve();
+                              });
+                      } catch (e) {
+                          reject(new Error('Failed to ping PackageKit daemon: %s'.format(e.toString())));
+                      }
+            });
+        });
+    }
+
+    async OpenAsync(parameters, invocation) {
         let [type, timestamp, totalSecondsToStayOpen, inhibitorObjectPaths] = parameters;
         this._totalSecondsToStayOpen = totalSecondsToStayOpen;
         this._type = type;
 
+        try {
+            await this._ensurePkOfflineProperties();
+        } catch (e) {
+            log(`Failed to ensure PackageKit proxy, offline updates will not work: ${e}`);
+        }
+
         // Only consider updates and upgrades if PackageKit is available.
         if (this._pkOfflineProxy && this._type == DialogType.RESTART) {
             if (this._pkOfflineProxy.UpdateTriggered)


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