loginManager: Add support for suspend()

Logind provides a Suspend method, which we should use instead of
the UPower API when available. Expose this in loginManager, using
the UPower API for the ConsoleKit implementation.

https://bugzilla.gnome.org/show_bug.cgi?id=686482
This commit is contained in:
Florian Müllner 2012-10-19 17:29:53 +02:00
parent 96556eb959
commit 1f183b8a4e

View File

@ -3,7 +3,9 @@
const GLib = imports.gi.GLib; const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio; const Gio = imports.gi.Gio;
const Lang = imports.lang; const Lang = imports.lang;
const Mainloop = imports.mainloop;
const Shell = imports.gi.Shell; const Shell = imports.gi.Shell;
const UPowerGlib = imports.gi.UPowerGlib;
const SystemdLoginManagerIface = <interface name='org.freedesktop.login1.Manager'> const SystemdLoginManagerIface = <interface name='org.freedesktop.login1.Manager'>
<method name='PowerOff'> <method name='PowerOff'>
@ -12,12 +14,18 @@ const SystemdLoginManagerIface = <interface name='org.freedesktop.login1.Manager
<method name='Reboot'> <method name='Reboot'>
<arg type='b' direction='in'/> <arg type='b' direction='in'/>
</method> </method>
<method name='Suspend'>
<arg type='b' direction='in'/>
</method>
<method name='CanPowerOff'> <method name='CanPowerOff'>
<arg type='s' direction='out'/> <arg type='s' direction='out'/>
</method> </method>
<method name='CanReboot'> <method name='CanReboot'>
<arg type='s' direction='out'/> <arg type='s' direction='out'/>
</method> </method>
<method name='CanSuspend'>
<arg type='s' direction='out'/>
</method>
</interface>; </interface>;
const SystemdLoginSessionIface = <interface name='org.freedesktop.login1.Session'> const SystemdLoginSessionIface = <interface name='org.freedesktop.login1.Session'>
@ -123,12 +131,25 @@ const LoginManagerSystemd = new Lang.Class({
}); });
}, },
canSuspend: function(asyncCallback) {
this._proxy.CanSuspendRemote(function(result, error) {
if (error)
asyncCallback(false);
else
asyncCallback(result[0] != 'no');
});
},
powerOff: function() { powerOff: function() {
this._proxy.PowerOffRemote(true); this._proxy.PowerOffRemote(true);
}, },
reboot: function() { reboot: function() {
this._proxy.RebootRemote(true); this._proxy.RebootRemote(true);
},
suspend: function() {
this._proxy.SuspendRemote(true);
} }
}); });
@ -139,6 +160,7 @@ const LoginManagerConsoleKit = new Lang.Class({
this._proxy = new ConsoleKitManager(Gio.DBus.system, this._proxy = new ConsoleKitManager(Gio.DBus.system,
'org.freedesktop.ConsoleKit', 'org.freedesktop.ConsoleKit',
'/org/freedesktop/ConsoleKit/Manager'); '/org/freedesktop/ConsoleKit/Manager');
this._upClient = new UPowerGlib.Client();
}, },
// Having this function is a bit of a hack since the Systemd and ConsoleKit // Having this function is a bit of a hack since the Systemd and ConsoleKit
@ -186,12 +208,22 @@ const LoginManagerConsoleKit = new Lang.Class({
}); });
}, },
canSuspend: function(asyncCallback) {
Mainloop.idle_add(Lang.bind(this, function() {
asyncCallback(this._upClient.get_can_suspend());
return false;
}));
},
powerOff: function() { powerOff: function() {
this._proxy.StopRemote(); this._proxy.StopRemote();
}, },
reboot: function() { reboot: function() {
this._proxy.RestartRemote(); this._proxy.RestartRemote();
},
suspend: function() {
this._upClient.suspend_sync(null);
} }
}); });