[gnome-shell-extensions] places-menu: make launching asynchronous
- From: Christian Kellner <gicmo src gnome org>
 
- To: commits-list gnome org
 
- Cc: 
 
- Subject: [gnome-shell-extensions] places-menu: make launching asynchronous
 
- Date: Fri, 28 Apr 2017 13:38:15 +0000 (UTC)
 
commit cfbb2a459be581469fc1d81b00cecda3f8a8726e
Author: Christian Kellner <christian kellner me>
Date:   Fri Apr 28 10:13:35 2017 +0200
    places-menu: make launching asynchronous
    
    Use the async version of Gio.AppInfo.launch_default_for_uri so
    we don't hang or block if the uri we are trying to launch the
    application for is on slow or dead network connections.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781831
 extensions/places-menu/placeDisplay.js |   38 +++++++++++++++++++++----------
 1 files changed, 26 insertions(+), 12 deletions(-)
---
diff --git a/extensions/places-menu/placeDisplay.js b/extensions/places-menu/placeDisplay.js
index 37d5965..3037900 100644
--- a/extensions/places-menu/placeDisplay.js
+++ b/extensions/places-menu/placeDisplay.js
@@ -44,20 +44,34 @@ const PlaceInfo = new Lang.Class({
         return false;
     },
 
+    _createLaunchCallback: function(launchContext, tryMount) {
+        return (_ignored, result) => {
+            try {
+                Gio.AppInfo.launch_default_for_uri_finish(result);
+            } catch(e if e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_MOUNTED)) {
+                this.file.mount_enclosing_volume(0, null, null, (file, result) => {
+                    file.mount_enclosing_volume_finish(result);
+                    if (tryMount) {
+                        let callback = this._createLaunchCallback(launchContext, false);
+                        Gio.AppInfo.launch_default_for_uri_async(file.get_uri(),
+                                                                 launchContext,
+                                                                 null,
+                                                                 callback);
+                    }
+                });
+            } catch(e) {
+                Main.notifyError(_("Failed to launch ā%sā").format(this.name), e.message);
+            }
+        }
+    },
+
     launch: function(timestamp) {
         let launchContext = global.create_app_launch_context(timestamp, -1);
-
-        try {
-            Gio.AppInfo.launch_default_for_uri(this.file.get_uri(),
-                                               launchContext);
-        } catch(e if e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_MOUNTED)) {
-            this.file.mount_enclosing_volume(0, null, null, function(file, result) {
-                file.mount_enclosing_volume_finish(result);
-                Gio.AppInfo.launch_default_for_uri(file.get_uri(), launchContext);
-            });
-        } catch(e) {
-            Main.notifyError(_("Failed to launch ā%sā").format(this.name), e.message);
-        }
+        let callback = this._createLaunchCallback(launchContext, true);
+        Gio.AppInfo.launch_default_for_uri_async(this.file.get_uri(),
+                                                 launchContext,
+                                                 null,
+                                                 callback);
     },
 
     getIcon: function() {
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]