Native Dart client library to access Ubuntu desktop session managers
The simplified API provides a small set of methods common among different Ubuntu desktop managers. It will try to detect the current desktop environment and invoke the methods provided by the respective session manager.
Currently provided methods:
logout()
reboot()
shutdown()
If the desktop environment is unknwon (or the API is not implemented yet..) it will use systemd-logind
as a fallback. Warning - the fallback API will not show a confirmation dialog for logout()
, reboot()
or shutdown()
.
You can use fallback: false
to disable the fallback.
import 'package:ubuntu_session/ubuntu_session.dart';
void main() {
final session = UbuntuSession();
print('Detected desktop environment: ${session.desktop}');
session.reboot();
}
import 'package:dbus/dbus.dart';
import 'package:ubuntu_session/ubuntu_session.dart';
void main() async {
final manager = GnomeSessionManager();
await manager.connect();
try {
await manager.reboot();
} on DBusMethodResponseException catch (e) {
print('Error: $e');
}
await manager.close();
}
Shutdown()
Reboot()
CanShutdown()
IsSessionRunning()
Logout()
Inhibit()
Uninhibit()
IsInhibited()
Renderer
SessionName
SessionIsActive
Please refer to the GNOME Session documentation for further details.
import 'package:dbus/dbus.dart';
import 'package:ubuntu_session/ubuntu_session.dart';
void main() async {
final manager = MateSessionManager();
await manager.connect();
try {
await manager.shutdown();
} on DBusMethodResponseException catch (e) {
print('Error: $e');
}
await manager.close();
}
Shutdown()
CanShutdown()
IsSessionRunning()
Logout()
Inhibit()
Uninhibit()
IsInhibited()
Renderer
Please refer to the GNOME Session documentation for further details.
Note that the MATE session manager only implements a subset of the org.gnome.SessionManager
interface
Since Reboot
is not provided by the MATE session manager, UbuntuSession().reboot()
invokes the Shutdown
method in the MATE desktop environment, as it shows a dialog that provides options to suspend, reboot and shutdown the system.
import 'package:ubuntu_session/ubuntu_session.dart';
void main() async {
final manager = SystemdSessionManager();
await manager.connect();
await manager.reboot(true);
await manager.close();
}
Halt()
Hibernate()
PowerOff()
Reboot()
Suspend()
CanHalt()
CanHibernate()
CanPowerOff()
CanReboot()
CanSuspend()
ListSessions()
Inhibit()
OnExternalPower
Lock()
Terminate()
Id
Active
Please refer to the systemd-logind documentation for further details.
We welcome contributions! See the contribution guide for more details.