registerWithAcceleratorAndCallback method

Shortcut? registerWithAcceleratorAndCallback(
  1. String accelerator,
  2. void callback()
)

Implementation

Shortcut? registerWithAcceleratorAndCallback(
  String accelerator,
  void Function() callback,
) {
  final acceleratorNative = accelerator.toNativeUtf8().cast<ffi.Char>();
  final callbackCallable =
      ffi.NativeCallable<
        ffi.Void Function(ffi.Pointer<ffi.Void>)
      >.isolateLocal((ffi.Pointer<ffi.Void> _) {
        callback();
      });
  final handle = c
      .native_shortcut_manager_register_with_accelerator_and_callback(
        acceleratorNative,
        callbackCallable.nativeFunction,
        NativeCallbacks.userData(callbackCallable),
        NativeCallbacks.release,
      );
  pkg_ffi.calloc.free(acceleratorNative);
  if (handle == 0) return null;
  return Shortcut.fromHandle(handle);
}