gamepads icon indicating copy to clipboard operation
gamepads copied to clipboard

feat: Added a stream to listen for connecting/disconnecting gamepads for MacOS

Open gotnull opened this issue 9 months ago • 2 comments

This Pull Request enhances the event handling functionality of the library by implementing methods to emit gamepad events and gamepad connection events for MacOS. Additionally, it defines stream controllers and streams for broadcasting these events.

Changes Made:

  • Added method emitGamepadConnectedEvent() to emit gamepad connection events.
  • Defined stream controller _gamepadConnectedStreamController to manage stream of gamepad connection events.
  • Added a GamepadConnectedEvent.
  • Implemented getter gamepadConnectedStream to provide access to the stream of gamepad connection events.
  • Added to the dispose() method to properly close the stream controller when it is no longer needed.
  • Updated the README.md for usage examples.

These changes enhance the functionality of the library by providing a structured approach to emitting and broadcasting gamepad events and connection events, facilitating seamless integration of gamepad functionality into applications.

Usage:

StreamSubscription<GamepadConnectedEvent>? _connectedGamepadSubscription;

_connectedGamepadSubscription = Gamepads.isConnected.listen((GamepadConnectedEvent event) {
  if (event.isConnected) {
      // ...
  }
});

gotnull avatar Apr 30 '24 11:04 gotnull

Worth flagging explicitly that this PR makes relevant changes to the Dart interface and contains implementation code for macOS only.

markvideon avatar May 01 '24 07:05 markvideon

Worth flagging explicitly that this PR makes relevant changes to the Dart interface and contains implementation code for macOS only.

Yeah, we should add all platforms if we're adding new features to the interface. Could you do the other implementations too @gotnull? :)

spydon avatar May 02 '24 08:05 spydon