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

@ -12,6 +12,7 @@ const GnomeSession = imports.misc.gnomeSession;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const Util = imports.misc.util;
// Adapted from gdm/gui/user-switch-applet/applet.c
//
@ -31,7 +32,7 @@ StatusMenuButton.prototype = {
this.actor.set_child(box);
this._gdm = Gdm.UserManager.ref_default();
this._gdm.queue_load()
this._gdm.queue_load();
this._user = this._gdm.get_user(GLib.get_user_name());
this._presence = new GnomeSession.Presence();
@ -153,17 +154,17 @@ StatusMenuButton.prototype = {
_onMyAccountActivate: function() {
Main.overview.hide();
this._spawn(['gnome-control-center', 'user-accounts']);
Util.spawnDesktop('gnome-user-accounts-panel');
},
_onPreferencesActivate: function() {
Main.overview.hide();
this._spawn(['gnome-control-center', '-o']);
Util.spawnDesktop('gnome-control-center');
},
_onLockScreenActivate: function() {
Main.overview.hide();
this._spawn(['gnome-screensaver-command', '--lock']);
Util.spawn(['gnome-screensaver-command', '--lock']);
},
_onLoginScreenActivate: function() {
@ -174,19 +175,11 @@ StatusMenuButton.prototype = {
_onQuitSessionActivate: function() {
Main.overview.hide();
this._spawn(['gnome-session-save', '--logout-dialog']);
Util.spawn(['gnome-session-save', '--logout-dialog']);
},
_onShutDownActivate: function() {
Main.overview.hide();
this._spawn(['gnome-session-save', '--shutdown-dialog']);
},
_spawn: function(args) {
// FIXME: once Shell.Process gets support for signalling
// errors we should pop up an error dialog or something here
// on failure
let p = new Shell.Process({'args' : args});
p.run();
Util.spawn(['gnome-session-save', '--shutdown-dialog']);
}
};