From 69dd5c85ef7dc38ba95db3e04c5b92d1509ed36c Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Mon, 3 Nov 2025 08:58:16 +0100 Subject: [PATCH] detect media keys on macOS / iOS #1 --- lib/bluetooth/connection.dart | 4 ++ linux/flutter/generated_plugin_registrant.cc | 4 ++ linux/flutter/generated_plugins.cmake | 1 + macos/Flutter/GeneratedPluginRegistrant.swift | 2 + macos/Podfile.lock | 6 +++ pubspec.lock | 40 +++++++++++++++++++ pubspec.yaml | 1 + .../flutter/generated_plugin_registrant.cc | 3 ++ windows/flutter/generated_plugins.cmake | 1 + 9 files changed, 62 insertions(+) diff --git a/lib/bluetooth/connection.dart b/lib/bluetooth/connection.dart index 05881b2..2e59f1e 100644 --- a/lib/bluetooth/connection.dart +++ b/lib/bluetooth/connection.dart @@ -6,6 +6,7 @@ import 'package:dartx/dartx.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:gamepads/gamepads.dart'; +import 'package:media_key_detector/media_key_detector.dart'; import 'package:swift_control/bluetooth/devices/bluetooth_device.dart'; import 'package:swift_control/bluetooth/devices/gamepad/gamepad_device.dart'; import 'package:swift_control/main.dart'; @@ -162,6 +163,9 @@ class Connection { if (settings.getMyWhooshLinkEnabled() && settings.getTrainerApp() is MyWhoosh && !whooshLink.isStarted.value) { startMyWhooshServer(); } + mediaKeyDetector.addListener((mediaKey) { + print('Media key pressed: $mediaKey'); + }); } Future startMyWhooshServer() { diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index 4f4e016..1c45750 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -23,6 +24,9 @@ void fl_register_plugins(FlPluginRegistry* registry) { g_autoptr(FlPluginRegistrar) gamepads_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "GamepadsLinuxPlugin"); gamepads_linux_plugin_register_with_registrar(gamepads_linux_registrar); + g_autoptr(FlPluginRegistrar) media_key_detector_linux_registrar = + fl_plugin_registry_get_registrar_for_plugin(registry, "MediaKeyDetectorPlugin"); + media_key_detector_plugin_register_with_registrar(media_key_detector_linux_registrar); g_autoptr(FlPluginRegistrar) screen_retriever_linux_registrar = fl_plugin_registry_get_registrar_for_plugin(registry, "ScreenRetrieverLinuxPlugin"); screen_retriever_linux_plugin_register_with_registrar(screen_retriever_linux_registrar); diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 35fdcfd..4f57d1b 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST bluetooth_low_energy_linux file_selector_linux gamepads_linux + media_key_detector_linux screen_retriever_linux url_launcher_linux window_manager diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index e36bc1e..59294bf 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -11,6 +11,7 @@ import file_selector_macos import flutter_local_notifications import gamepads_darwin import keypress_simulator_macos +import media_key_detector_macos import package_info_plus import path_provider_foundation import screen_retriever_macos @@ -27,6 +28,7 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FlutterLocalNotificationsPlugin.register(with: registry.registrar(forPlugin: "FlutterLocalNotificationsPlugin")) GamepadsDarwinPlugin.register(with: registry.registrar(forPlugin: "GamepadsDarwinPlugin")) KeypressSimulatorMacosPlugin.register(with: registry.registrar(forPlugin: "KeypressSimulatorMacosPlugin")) + MediaKeyDetectorPlugin.register(with: registry.registrar(forPlugin: "MediaKeyDetectorPlugin")) FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) ScreenRetrieverMacosPlugin.register(with: registry.registrar(forPlugin: "ScreenRetrieverMacosPlugin")) diff --git a/macos/Podfile.lock b/macos/Podfile.lock index 4bfbc2f..c2b94d9 100644 --- a/macos/Podfile.lock +++ b/macos/Podfile.lock @@ -13,6 +13,8 @@ PODS: - FlutterMacOS - keypress_simulator_macos (0.0.1): - FlutterMacOS + - media_key_detector_macos (0.0.1): + - FlutterMacOS - package_info_plus (0.0.1): - FlutterMacOS - path_provider_foundation (0.0.1): @@ -41,6 +43,7 @@ DEPENDENCIES: - FlutterMacOS (from `Flutter/ephemeral`) - gamepads_darwin (from `Flutter/ephemeral/.symlinks/plugins/gamepads_darwin/macos`) - keypress_simulator_macos (from `Flutter/ephemeral/.symlinks/plugins/keypress_simulator_macos/macos`) + - media_key_detector_macos (from `Flutter/ephemeral/.symlinks/plugins/media_key_detector_macos/macos`) - package_info_plus (from `Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos`) - path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`) - screen_retriever_macos (from `Flutter/ephemeral/.symlinks/plugins/screen_retriever_macos/macos`) @@ -65,6 +68,8 @@ EXTERNAL SOURCES: :path: Flutter/ephemeral/.symlinks/plugins/gamepads_darwin/macos keypress_simulator_macos: :path: Flutter/ephemeral/.symlinks/plugins/keypress_simulator_macos/macos + media_key_detector_macos: + :path: Flutter/ephemeral/.symlinks/plugins/media_key_detector_macos/macos package_info_plus: :path: Flutter/ephemeral/.symlinks/plugins/package_info_plus/macos path_provider_foundation: @@ -90,6 +95,7 @@ SPEC CHECKSUMS: FlutterMacOS: d0db08ddef1a9af05a5ec4b724367152bb0500b1 gamepads_darwin: 07af6c60c282902b66574c800e20b2b26e68fda8 keypress_simulator_macos: f8556f9101f9f2f175652e0bceddf0fe82a4c6b2 + media_key_detector_macos: a93757a483b4b47283ade432b1af9e427c47329f package_info_plus: 12f1c5c2cfe8727ca46cbd0b26677728972d9a5b path_provider_foundation: 0b743cbb62d8e47eab856f09262bb8c1ddcfe6ba screen_retriever_macos: 776e0fa5d42c6163d2bf772d22478df4b302b161 diff --git a/pubspec.lock b/pubspec.lock index 83bfb90..f660e55 100755 --- a/pubspec.lock +++ b/pubspec.lock @@ -620,6 +620,46 @@ packages: url: "https://pub.dev" source: hosted version: "0.11.1" + media_key_detector: + dependency: "direct main" + description: + name: media_key_detector + sha256: "397150df1e60e2a813370248bb6f55405794960e6078ddac8bd96f8a763a16d1" + url: "https://pub.dev" + source: hosted + version: "0.0.1" + media_key_detector_linux: + dependency: transitive + description: + name: media_key_detector_linux + sha256: de4a0e898a0d045bc82902880487d05bd59783b0acd6996463fe57c90ecd0374 + url: "https://pub.dev" + source: hosted + version: "0.0.1" + media_key_detector_macos: + dependency: transitive + description: + name: media_key_detector_macos + sha256: c2513c9c4cc97c8d2ce8378918c7daf3937f90976352452a640c2cdb1df4636e + url: "https://pub.dev" + source: hosted + version: "0.0.1" + media_key_detector_platform_interface: + dependency: transitive + description: + name: media_key_detector_platform_interface + sha256: "081b36b74d47f21e5e03435b038434cc3b58c501e47daf7885aa4615bcaf8836" + url: "https://pub.dev" + source: hosted + version: "0.0.1" + media_key_detector_windows: + dependency: transitive + description: + name: media_key_detector_windows + sha256: "3bfa26a8b24947805aa3f19ca621ce8c57d3cf2f22de2630d8fa01f064d62c8a" + url: "https://pub.dev" + source: hosted + version: "0.0.1" meta: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 3b7e6ff..71ca368 100755 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -35,6 +35,7 @@ dependencies: path: keypress_simulator/packages/keypress_simulator shared_preferences: ^2.5.3 flex_color_scheme: ^8.3.0 + media_key_detector: ^0.0.1 accessibility: path: accessibility diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 8d7dd6c..0770171 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +26,8 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { registry->GetRegistrarForPlugin("GamepadsWindowsPluginCApi")); KeypressSimulatorWindowsPluginCApiRegisterWithRegistrar( registry->GetRegistrarForPlugin("KeypressSimulatorWindowsPluginCApi")); + MediaKeyDetectorWindowsRegisterWithRegistrar( + registry->GetRegistrarForPlugin("MediaKeyDetectorWindows")); PermissionHandlerWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); ScreenRetrieverWindowsPluginCApiRegisterWithRegistrar( diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 8e22eef..911d77d 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -7,6 +7,7 @@ list(APPEND FLUTTER_PLUGIN_LIST file_selector_windows gamepads_windows keypress_simulator_windows + media_key_detector_windows permission_handler_windows screen_retriever_windows universal_ble