diff --git a/js/Makefile.am b/js/Makefile.am index 4c41bffee..14a25b599 100644 --- a/js/Makefile.am +++ b/js/Makefile.am @@ -7,6 +7,7 @@ nobase_dist_js_DATA = \ gdm/fingerprint.js \ gdm/loginDialog.js \ gdm/powerMenu.js \ + gdm/systemd.js \ extensionPrefs/main.js \ misc/config.js \ misc/docInfo.js \ diff --git a/js/gdm/powerMenu.js b/js/gdm/powerMenu.js index efe1a8f93..59ebc42e6 100644 --- a/js/gdm/powerMenu.js +++ b/js/gdm/powerMenu.js @@ -22,6 +22,8 @@ const Lang = imports.lang; const UPowerGlib = imports.gi.UPowerGlib; const ConsoleKit = imports.gdm.consoleKit; +const Systemd = imports.gdm.systemd; + const PanelMenu = imports.ui.panelMenu; const PopupMenu = imports.ui.popupMenu; @@ -32,6 +34,7 @@ const PowerMenuButton = new Lang.Class({ _init: function() { this.parent('system-shutdown', null); this._consoleKitManager = new ConsoleKit.ConsoleKitManager(); + this._systemdLoginManager = new Systemd.SystemdLoginManager(); this._upClient = new UPowerGlib.Client(); this._createSubMenu(); @@ -61,39 +64,75 @@ const PowerMenuButton = new Lang.Class({ }, _updateHaveShutdown: function() { - this._consoleKitManager.CanStopRemote(Lang.bind(this, - function(result, error) { - if (!error) - this._haveShutdown = result; - else - this._haveShutdown = false; - if (this._haveShutdown) { - this._powerOffItem.actor.show(); - } else { - this._powerOffItem.actor.hide(); - } + if (Systemd.haveSystemd()) { + this._systemdLoginManager.CanPowerOffRemote(Lang.bind(this, + function(result, error) { + if (!error) + this._haveShutdown = result != 'no'; + else + this._haveShutdown = false; - this._updateVisibility(); - })); + if (this._haveShutdown) + this._powerOffItem.actor.show(); + else + this._powerOffItem.actor.hide(); + + this._updateVisibility(); + })); + } else { + this._consoleKitManager.CanStopRemote(Lang.bind(this, + function(result, error) { + if (!error) + this._haveShutdown = result; + else + this._haveShutdown = false; + + if (this._haveShutdown) { + this._powerOffItem.actor.show(); + } else { + this._powerOffItem.actor.hide(); + } + + this._updateVisibility(); + })); + } }, _updateHaveRestart: function() { - this._consoleKitManager.CanRestartRemote(Lang.bind(this, - function(result, error) { - if (!error) - this._haveRestart = result; - else - this._haveRestart = false; - if (this._haveRestart) { - this._restartItem.actor.show(); - } else { - this._restartItem.actor.hide(); - } + if (Systemd.haveSystemd()) { + this._systemdLoginManager.CanRebootRemote(Lang.bind(this, + function(result, error) { + if (!error) + this._haveRestart = result != 'no'; + else + this._haveRestart = false; - this._updateVisibility(); - })); + if (this._haveRestart) + this._restartItem.actor.show(); + else + this._restartItem.actor.hide(); + + this._updateVisibility(); + })); + } else { + this._consoleKitManager.CanRestartRemote(Lang.bind(this, + function(result, error) { + if (!error) + this._haveRestart = result; + else + this._haveRestart = false; + + if (this._haveRestart) { + this._restartItem.actor.show(); + } else { + this._restartItem.actor.hide(); + } + + this._updateVisibility(); + })); + } }, _updateHaveSuspend: function() { @@ -132,12 +171,22 @@ const PowerMenuButton = new Lang.Class({ }, _onActivateRestart: function() { - if (this._haveRestart) + if (!this._haveRestart) + return; + + if (Systemd.haveSystemd()) + this._systemdLoginManager.RebootRemote(true); + else this._consoleKitManager.RestartRemote(); }, _onActivatePowerOff: function() { - if (this._haveShutdown) + if (!this._haveShutdown) + return; + + if (Systemd.haveSystemd()) + this._systemdLoginManager.PowerOffRemote(true); + else this._consoleKitManager.StopRemote(); } }); diff --git a/js/gdm/systemd.js b/js/gdm/systemd.js new file mode 100644 index 000000000..8dd73abee --- /dev/null +++ b/js/gdm/systemd.js @@ -0,0 +1,31 @@ +// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*- + +const GLib = imports.gi.GLib; +const Gio = imports.gi.Gio; + +const SystemdLoginManagerIface = + + + + + + + + + + + + +; + +const SystemdLoginManagerProxy = Gio.DBusProxy.makeProxyWrapper(SystemdLoginManagerIface); + +function SystemdLoginManager() { + return new SystemdLoginManagerProxy(Gio.DBus.system, + 'org.freedesktop.login1', + '/org/freedesktop/login1'); +}; + +function haveSystemd() { + return GLib.access("/sys/fs/cgroup/systemd", 0) >= 0; +}