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



commit 253b275093873c6b790781e55efed873f81ebaf0
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 | 59 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 58 insertions(+), 1 deletion(-)
---
diff --git a/js/ui/endSessionDialog.js b/js/ui/endSessionDialog.js
index 42ae0d3f26..7c3b565533 100644
--- a/js/ui/endSessionDialog.js
+++ b/js/ui/endSessionDialog.js
@@ -608,11 +608,68 @@ class EndSessionDialog extends ModalDialog.ModalDialog {
         });
     }
 
-    OpenAsync(parameters, invocation) {
+    _ensurePkOfflineProperties() {
+        return new Promise((resolutionFunc, rejectedFunc) => {
+            // If PackageKit is not installed, or if it is running, we're done.
+            if (this._pkOfflineProxy == null || this._pkOfflineProxy.g_name_owner != null) {
+                resolutionFunc();
+                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 propertiesChangedID = 0;
+            let timeoutID = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
+                pkLaunchTimeout,
+                () => {
+                    log('Timed out waiting for PackageKit daemon to refresh properties');
+                    this._pkOfflineProxy.disconnect(propertiesChangedID);
+                    rejectedFunc();
+                    return GLib.SOURCE_REMOVE;
+                });
+
+            propertiesChangedID = this._pkOfflineProxy.connect(
+                'g-properties-changed',
+                (unusedChanged, unusedInvalidated) => {
+                    // FIXME: check changed for the properties we use.
+                    this._pkOfflineProxy.disconnect(propertiesChangedID);
+                    GLib.Source.remove(timeoutID);
+                    resolutionFunc();
+                });
+
+            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);
+                          } catch (e) {
+                              log('Failed to ping PackageKit daemon: %s'.format(e.toString()));
+                              GLib.Source.remove(timeoutID);
+                              this._pkOfflineProxy.disconnect(propertiesChangedID);
+                              rejectedFunc();
+                          }
+                      });
+        });
+    }
+
+    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');
+        }
+
         // 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]