From 62225915841129e9829623014cac4f79e13d35f9 Mon Sep 17 00:00:00 2001 From: Buddy Jonte Date: Thu, 3 Sep 2026 15:21:16 +0200 Subject: [PATCH] Identify gamepads by vendor and product id from the start --- .../gamepad/gamepad_device_directory.dart | 6 ++- packages/nesd/pubspec.yaml | 2 +- .../gamepad_device_directory_test.dart | 43 +++++++++++++++++++ pubspec.lock | 34 ++++++--------- 4 files changed, 62 insertions(+), 23 deletions(-) diff --git a/packages/nesd/lib/ui/emulator/input/gamepad/gamepad_device_directory.dart b/packages/nesd/lib/ui/emulator/input/gamepad/gamepad_device_directory.dart index f261a6af..ecb62f16 100644 --- a/packages/nesd/lib/ui/emulator/input/gamepad/gamepad_device_directory.dart +++ b/packages/nesd/lib/ui/emulator/input/gamepad/gamepad_device_directory.dart @@ -18,7 +18,11 @@ Future> defaultGamepadDeviceLookup() async { final devices = { for (final controller in controllers) - controller.id: GamepadDeviceKey(name: controller.name), + controller.id: GamepadDeviceKey( + name: controller.name, + vendorId: controller.vendorId, + productId: controller.productId, + ), }; for (final controller in controllers) { diff --git a/packages/nesd/pubspec.yaml b/packages/nesd/pubspec.yaml index 7cd2016c..fb2bc239 100644 --- a/packages/nesd/pubspec.yaml +++ b/packages/nesd/pubspec.yaml @@ -25,7 +25,7 @@ dependencies: flutter_material_design_icons: ^3.1.0+7447 flutter_riverpod: ^3.4.3 freezed_annotation: ^3.1.0 - gamepads: ^0.1.11 + gamepads: ^0.1.12 hooks_riverpod: ^3.4.3 idb_shim: ^2.9.9 image: ^4.10.1 diff --git a/packages/nesd/test/ui/emulator/input/gamepad/gamepad_device_directory_test.dart b/packages/nesd/test/ui/emulator/input/gamepad/gamepad_device_directory_test.dart index 92b0004f..d9521308 100644 --- a/packages/nesd/test/ui/emulator/input/gamepad/gamepad_device_directory_test.dart +++ b/packages/nesd/test/ui/emulator/input/gamepad/gamepad_device_directory_test.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:gamepads/gamepads.dart'; import 'package:nesd/ui/emulator/input/gamepad/gamepad_device_directory.dart'; @@ -8,6 +9,8 @@ import 'package:nesd/ui/emulator/input/gamepad/gamepad_input_mapper.dart'; import 'package:nesd/ui/emulator/input/gamepad/gamepad_slot_registry.dart'; void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + const dualSense = GamepadDeviceKey( name: 'Sony DualSense', vendorId: 1356, @@ -187,4 +190,44 @@ void main() { expect(registry.slotOf('0'), 0); expect(calls, 1); }); + + group('the default lookup', () { + const channel = MethodChannel('xyz.luan/gamepads'); + + final messenger = + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger; + + void listGamepads(List> gamepads) => + messenger.setMockMethodCallHandler( + channel, + (call) async => call.method == 'listGamepads' ? gamepads : null, + ); + + tearDown(() => messenger.setMockMethodCallHandler(channel, null)); + + test('carries the ids the platform reports', () async { + listGamepads([ + { + 'id': '0', + 'name': 'Sony DualSense', + 'vendorId': 1356, + 'productId': 3302, + }, + ]); + + expect(await defaultGamepadDeviceLookup(), {'0': dualSense}); + }); + + test('leaves the ids null where the platform has none', () async { + listGamepads([ + {'id': '0', 'name': 'Sony Interactive Entertainment - DualSense'}, + ]); + + expect(await defaultGamepadDeviceLookup(), { + '0': const GamepadDeviceKey( + name: 'Sony Interactive Entertainment - DualSense', + ), + }); + }); + }); } diff --git a/pubspec.lock b/pubspec.lock index 3e88576f..41a22939 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -428,31 +428,23 @@ packages: dependency: transitive description: name: gamepads - sha256: "8134c967c29496cbc20e73c88b31c6d11765e846b8e465c52b436fe6e88339ce" + sha256: "212cafc5d240b5067eee2a0650b903ddbc18eafbc71a0d1064f8c06587db8ea6" url: "https://pub.dev" source: hosted - version: "0.1.11" + version: "0.1.12" gamepads_android: dependency: transitive description: name: gamepads_android - sha256: f3a600e1212374771bdd47206088940a36fb75791b3c4223eccfa487dfd1ed0f + sha256: c50ccad8cd5dab70b9a1eda11862f2756da2a82005b9b580fbb0f4b2c0fbd3a2 url: "https://pub.dev" source: hosted - version: "0.1.9" + version: "0.1.10" gamepads_darwin: dependency: transitive description: name: gamepads_darwin - sha256: "113d50ad327aa5f1b5df6807310a4f23865c01330f7a62d5c53c9df8933f948a" - url: "https://pub.dev" - source: hosted - version: "0.1.3" - gamepads_ios: - dependency: transitive - description: - name: gamepads_ios - sha256: "9a65f16797c7479d2bc6d7967d45e8b2448c6302b128fcf3231460f839021a37" + sha256: ab7d2c8ee84ffc989a8c942204c1bc2d6c6585dfa640a30c5e72ef5e4cdf8c91 url: "https://pub.dev" source: hosted version: "0.1.4" @@ -460,34 +452,34 @@ packages: dependency: transitive description: name: gamepads_linux - sha256: "80bf70df6da6185926e6d8b2feb98e725e6fe99290afafaea91dba471e8c1c1e" + sha256: ec986955e9cbe505c0874bb960ec6a87d8c2c31e30ff5453d4c9be2020eac097 url: "https://pub.dev" source: hosted - version: "0.1.2" + version: "0.1.3" gamepads_platform_interface: dependency: transitive description: name: gamepads_platform_interface - sha256: "9ddb3b61c780284a17739d759929d2e32b912d12d9145ee493ffe2b43fc6256a" + sha256: "51b243f64c3d02900ac37eef0ed0177710ef5b0a1265dbf46bb93ca0f4200f17" url: "https://pub.dev" source: hosted - version: "0.1.3" + version: "0.1.4" gamepads_web: dependency: transitive description: name: gamepads_web - sha256: "4f044a6003b34a8d5c5854924fbbfd64b6653bcb49169cf2aca26938f812672e" + sha256: "5ceaa635cdba536f1ee2b650227c39f5e4a8b1ec6588b00ea0ea6e7291d8e62e" url: "https://pub.dev" source: hosted - version: "0.1.2" + version: "0.1.3" gamepads_windows: dependency: transitive description: name: gamepads_windows - sha256: ecd1dc845a0ad6260a3016cd74f3e365c4006a458ae2c5c5eed7a72d33dd5738 + sha256: "2caf3abda6fe5a7ff7f434b00e71cfc823b594ef30326b7347e4635f1f0bad9c" url: "https://pub.dev" source: hosted - version: "0.3.1" + version: "0.3.2" glob: dependency: transitive description: