toggle method

  1. @override
Future<void> toggle({
  1. required bool enable,
})
override

Toggles the wakelock based on the given enable value.

Implementation

@override
Future<void> toggle({required bool enable}) async {
  if (enable) {
    _cookie = await _object
        .callMethod(
          'org.freedesktop.ScreenSaver',
          'Inhibit',
          [DBusString(await _appName), const DBusString('wakelock')],
          replySignature: DBusSignature.uint32,
        )
        .then((response) => response.returnValues.single.asUint32());
  } else if (_cookie != null) {
    await _object.callMethod(
      'org.freedesktop.ScreenSaver',
      'UnInhibit',
      [DBusUint32(_cookie!)],
      replySignature: DBusSignature.empty,
    );
    _cookie = null;
  }
}