runDialog: catch exceptions from Gio.app_info_launch_default_for_uri()

An uncaught exception here would mean that the dialog wouldn't close.

https://bugzilla.gnome.org/show_bug.cgi?id=653700
This commit is contained in:
Rui Matos 2011-07-06 20:43:49 +01:00
parent 1625591598
commit d12dd1491f

View File

@ -333,33 +333,46 @@ __proto__: ModalDialog.ModalDialog.prototype,
if (GLib.file_test(path, GLib.FileTest.EXISTS)) { if (GLib.file_test(path, GLib.FileTest.EXISTS)) {
let file = Gio.file_new_for_path(path); let file = Gio.file_new_for_path(path);
Gio.app_info_launch_default_for_uri(file.get_uri(), try {
global.create_app_launch_context()); Gio.app_info_launch_default_for_uri(file.get_uri(),
} else { global.create_app_launch_context());
this._commandError = true; } catch (e) {
// The exception from gjs contains an error string like:
this._errorMessage.set_text(e.message); // Error invoking Gio.app_info_launch_default_for_uri: No application
// is registered as handling this file
if (!this._errorBox.visible) { // We are only interested in the part after the first colon.
let [errorBoxMinHeight, errorBoxNaturalHeight] = this._errorBox.get_preferred_height(-1); let message = e.message.replace(/[^:]*: *(.+)/, '$1');
this._showError(message);
let parentActor = this._errorBox.get_parent();
Tweener.addTween(parentActor,
{ height: parentActor.height + errorBoxNaturalHeight,
time: DIALOG_GROW_TIME,
transition: 'easeOutQuad',
onComplete: Lang.bind(this,
function() {
parentActor.set_height(-1);
this._errorBox.show();
})
});
} }
} else {
this._showError(e.message);
} }
} }
} }
}, },
_showError : function(message) {
this._commandError = true;
this._errorMessage.set_text(message);
if (!this._errorBox.visible) {
let [errorBoxMinHeight, errorBoxNaturalHeight] = this._errorBox.get_preferred_height(-1);
let parentActor = this._errorBox.get_parent();
Tweener.addTween(parentActor,
{ height: parentActor.height + errorBoxNaturalHeight,
time: DIALOG_GROW_TIME,
transition: 'easeOutQuad',
onComplete: Lang.bind(this,
function() {
parentActor.set_height(-1);
this._errorBox.show();
})
});
}
},
open: function() { open: function() {
this._history.lastItem(); this._history.lastItem();
this._errorBox.hide(); this._errorBox.hide();