From cfbb2a459be581469fc1d81b00cecda3f8a8726e Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Fri, 28 Apr 2017 10:13:35 +0200 Subject: [PATCH] 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 file changed, 26 insertions(+), 12 deletions(-) diff --git a/extensions/places-menu/placeDisplay.js b/extensions/places-menu/placeDisplay.js index 37d59657..3037900c 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() {