isAvailable method

  1. @override
Future<bool> isAvailable()
override

Whether the keychain can be used now: a probe item is written and deleted. A locked keychain, a missing D-Bus session or tool, or a Windows logon without credentials answer false; never a prompt.

Implementation

@override
Future<bool> isAvailable() async {
  if (_os == 'linux' && (_env['DBUS_SESSION_BUS_ADDRESS'] ?? '').isEmpty) {
    return false;
  }
  const probe = 'tom.availability-probe';
  try {
    await write(probe, 'probe');
    final back = await read(probe);
    await delete(probe);
    return back == 'probe';
  } on Object {
    return false;
  }
}