util: add Util.spawn and friends

Add Util.spawn, Util.spawnCommandLine, and Util.spawnDesktop for
spawning a command/argv/.desktop file in the background, automatically
handling errors via MessageTray.SystemNotificationSource(), and
Util.trySpawn, Util.trySpawnCommandLine, and Utils.trySpawnDesktop
that don't do automatic error handling (but do at least clean up the
error message in the exception a bit).

Update various other bits of code around the shell to use the new
methods.

https://bugzilla.gnome.org/show_bug.cgi?id=635089
This commit is contained in:
Dan Winship
2010-11-17 11:43:08 -05:00
parent a65a0f03d4
commit 8bdfb8df68
10 changed files with 158 additions and 42 deletions

View File

@ -14,6 +14,7 @@ const _ = Gettext.gettext;
const Lightbox = imports.ui.lightbox;
const Main = imports.ui.main;
const Tweener = imports.ui.tweener;
const Util = imports.misc.util;
const MAX_FILE_DELETED_BEFORE_INVALID = 10;
@ -354,9 +355,7 @@ RunDialog.prototype = {
try {
if (inTerminal)
command = 'gnome-terminal -x ' + input;
let [ok, len, args] = GLib.shell_parse_argv(command);
let p = new Shell.Process({ 'args' : args });
p.run();
Util.trySpawnCommandLine(command);
} catch (e) {
// Mmmh, that failed - see if @input matches an existing file
let path = null;
@ -374,13 +373,8 @@ RunDialog.prototype = {
global.create_app_launch_context());
} else {
this._commandError = true;
// The exception contains an error string like:
// Error invoking Shell.run: Failed to execute child
// process "foo" (No such file or directory)
// We are only interested in the actual error, so parse
//that out.
let m = /.+\((.+)\)/.exec(e);
let errorStr = _("Execution of '%s' failed:").format(command) + '\n' + m[1];
let errorStr = _("Execution of '%s' failed:").format(command) + '\n' + e.message;
this._errorMessage.set_text(errorStr);
this._errorBox.show();