register method
Implementation
@override
Future<void> register(HotKey hotKey) {
final attempt = _PlatformRegistrationAttempt(hotKey);
_attempts.add(attempt);
return _enqueue(() async {
try {
if (attempt.cancelled) {
throw PlatformException(
code: 'registration_cancelled',
message: 'Hotkey registration was cancelled.',
);
}
final accelerator = hotKeyAccelerator(hotKey);
final previous = _hotKeys[hotKey.identifier];
final registration =
_accelerators[accelerator] ?? _backend.register(hotKey);
final id = registration is Future<int>
? await registration
: registration;
_accelerators[accelerator] = id;
_hotKeys[hotKey.identifier] = (hotKey, id, accelerator);
if (previous != null) {
try {
_release(previous);
} catch (_) {
_hotKeys[hotKey.identifier] = previous;
if (id != previous.$2 &&
!_hotKeys.values.any((other) => other.$2 == id)) {
_accelerators.remove(accelerator);
try {
_backend.unregister(id);
} catch (_) {
// Backend ownership survives until unregisterAll can retry.
}
}
rethrow;
}
}
} finally {
_attempts.remove(attempt);
}
});
}