From 1029c00a48f83c37a5e370c62265b817dfd1f618 Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Thu, 18 Dec 2025 08:11:06 +0100 Subject: [PATCH 1/5] teaser new connection methods --- lib/i10n/intl_en.arb | 4 +++- lib/pages/configuration.dart | 20 ++++++++++++++++++-- lib/utils/keymap/apps/my_whoosh.dart | 1 + lib/utils/keymap/apps/rouvy.dart | 7 ++++--- lib/utils/keymap/apps/supported_app.dart | 2 ++ 5 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/i10n/intl_en.arb b/lib/i10n/intl_en.arb index b9e79381..36e0ba70 100644 --- a/lib/i10n/intl_en.arb +++ b/lib/i10n/intl_en.arb @@ -404,5 +404,7 @@ "noConnectionMethodIsConnectedOrActive": "No connection method is connected or active.", "noActionAssignedForButton": "Could not perform {button}: No action assigned", "couldNotPerformButtonnamesplitbyuppercaseNoKeymapSet": "Could not perform {button}: No keymap set", - "purchase": "Purchase" + "purchase": "Purchase", + "openBikeControlAnnouncement": "Great news - {trainerApp} supports the OpenBikeControl Protocol, so you'll have the best possible experience!", + "newConnectionMethodAnnouncement": "{trainerApp} will soon support much better an reliable connection methods - stay tuned for updates!" } diff --git a/lib/pages/configuration.dart b/lib/pages/configuration.dart index e4749d80..3d3252e2 100644 --- a/lib/pages/configuration.dart +++ b/lib/pages/configuration.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:bike_control/gen/l10n.dart'; import 'package:bike_control/main.dart'; import 'package:bike_control/pages/button_edit.dart'; import 'package:bike_control/utils/core.dart'; @@ -127,8 +128,23 @@ class _ConfigurationPageState extends State { if (core.settings.getTrainerApp() != null) ...[ if (core.settings.getTrainerApp()!.supportsOpenBikeProtocol == true) Text( - 'Great news - ${core.settings.getTrainerApp()!.name} supports the OpenBikeControl Protocol, so you\'ll the best possible experience!', - ).xSmall, + AppLocalizations.of(context).openBikeControlAnnouncement(core.settings.getTrainerApp()!.name), + ).xSmall + else if (core.settings.getTrainerApp()!.star == true) + Row( + spacing: 8, + children: [ + Icon(Icons.star), + Expanded( + child: Text( + AppLocalizations.of( + context, + ).newConnectionMethodAnnouncement(core.settings.getTrainerApp()!.name), + style: TextStyle(fontWeight: FontWeight.bold), + ), + ), + ], + ), SizedBox(height: 8), Text( context.i18n.selectTargetWhereAppRuns( diff --git a/lib/utils/keymap/apps/my_whoosh.dart b/lib/utils/keymap/apps/my_whoosh.dart index 77dbf99b..6e65a6b2 100644 --- a/lib/utils/keymap/apps/my_whoosh.dart +++ b/lib/utils/keymap/apps/my_whoosh.dart @@ -15,6 +15,7 @@ class MyWhoosh extends SupportedApp { compatibleTargets: Target.values, supportsZwiftEmulation: false, supportsOpenBikeProtocol: screenshotMode, + star: true, keymap: Keymap( keyPairs: [ ...ControllerButton.values diff --git a/lib/utils/keymap/apps/rouvy.dart b/lib/utils/keymap/apps/rouvy.dart index 23b23b16..6fc1a7f3 100644 --- a/lib/utils/keymap/apps/rouvy.dart +++ b/lib/utils/keymap/apps/rouvy.dart @@ -1,12 +1,12 @@ import 'dart:io'; -import 'package:dartx/dartx.dart'; -import 'package:flutter/foundation.dart'; -import 'package:flutter/services.dart'; import 'package:bike_control/bluetooth/devices/zwift/constants.dart'; import 'package:bike_control/utils/keymap/apps/supported_app.dart'; import 'package:bike_control/utils/keymap/buttons.dart'; import 'package:bike_control/utils/requirements/multi.dart'; +import 'package:dartx/dartx.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; import '../keymap.dart'; @@ -17,6 +17,7 @@ class Rouvy extends SupportedApp { packageName: "eu.virtualtraining.rouvy.android", compatibleTargets: !kIsWeb && Platform.isIOS ? [Target.otherDevice] : Target.values, supportsZwiftEmulation: !kIsWeb && Platform.isAndroid, + star: true, keymap: Keymap( keyPairs: [ // https://support.rouvy.com/hc/de/articles/32452137189393-Virtuelles-Schalten#h_01K5GMVG4KVYZ0Y6W7RBRZC9MA diff --git a/lib/utils/keymap/apps/supported_app.dart b/lib/utils/keymap/apps/supported_app.dart index 16a36bec..5436115d 100644 --- a/lib/utils/keymap/apps/supported_app.dart +++ b/lib/utils/keymap/apps/supported_app.dart @@ -16,6 +16,7 @@ abstract class SupportedApp { final Keymap keymap; final bool supportsZwiftEmulation; final bool supportsOpenBikeProtocol; + final bool star; const SupportedApp({ required this.name, @@ -24,6 +25,7 @@ abstract class SupportedApp { required this.compatibleTargets, required this.supportsZwiftEmulation, this.supportsOpenBikeProtocol = false, + this.star = false, }); static final List supportedApps = [ From 73196323345c7c0527fd721a37f6032a452ae311 Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Thu, 18 Dec 2025 08:33:04 +0100 Subject: [PATCH 2/5] move button simulator page button --- lib/bluetooth/devices/mywhoosh/link.dart | 4 +- .../openbikecontrol/obc_ble_emulator.dart | 4 +- .../openbikecontrol/obc_mdns_emulator.dart | 4 +- .../devices/zwift/ftms_mdns_emulator.dart | 10 ++- .../devices/zwift/zwift_emulator.dart | 4 +- lib/bluetooth/remote_pairing.dart | 10 ++- lib/i10n/intl_en.arb | 4 +- lib/pages/button_simulator.dart | 86 +++++++++++++------ lib/pages/device.dart | 68 ++++----------- lib/pages/trainer.dart | 29 ++++++- lib/utils/core.dart | 9 ++ 11 files changed, 143 insertions(+), 89 deletions(-) diff --git a/lib/bluetooth/devices/mywhoosh/link.dart b/lib/bluetooth/devices/mywhoosh/link.dart index e9073cf3..ece136df 100644 --- a/lib/bluetooth/devices/mywhoosh/link.dart +++ b/lib/bluetooth/devices/mywhoosh/link.dart @@ -16,9 +16,11 @@ class WhooshLink extends TrainerConnection { Socket? _socket; ServerSocket? _server; + static const String connectionTitle = 'MyWhoosh Link'; + WhooshLink() : super( - title: 'MyWhoosh Link', + title: connectionTitle, supportedActions: [ InGameAction.shiftUp, InGameAction.shiftDown, diff --git a/lib/bluetooth/devices/openbikecontrol/obc_ble_emulator.dart b/lib/bluetooth/devices/openbikecontrol/obc_ble_emulator.dart index aa7fe525..b141723c 100644 --- a/lib/bluetooth/devices/openbikecontrol/obc_ble_emulator.dart +++ b/lib/bluetooth/devices/openbikecontrol/obc_ble_emulator.dart @@ -24,9 +24,11 @@ class OpenBikeControlBluetoothEmulator extends TrainerConnection { late GATTCharacteristic _buttonCharacteristic; + static const String connectionTitle = 'OpenBikeControl BLE Emulator'; + OpenBikeControlBluetoothEmulator() : super( - title: 'OpenBikeControl BLE Emulator', + title: connectionTitle, supportedActions: InGameAction.values, ); diff --git a/lib/bluetooth/devices/openbikecontrol/obc_mdns_emulator.dart b/lib/bluetooth/devices/openbikecontrol/obc_mdns_emulator.dart index a9b166d2..6eb51598 100644 --- a/lib/bluetooth/devices/openbikecontrol/obc_mdns_emulator.dart +++ b/lib/bluetooth/devices/openbikecontrol/obc_mdns_emulator.dart @@ -18,13 +18,15 @@ class OpenBikeControlMdnsEmulator extends TrainerConnection { ServerSocket? _server; Registration? _mdnsRegistration; + static const String connectionTitle = 'OpenBikeControl mDNS Emulator'; + final ValueNotifier connectedApp = ValueNotifier(null); Socket? _socket; OpenBikeControlMdnsEmulator() : super( - title: 'OpenBikeControl mDNS Emulator', + title: connectionTitle, supportedActions: InGameAction.values, ); diff --git a/lib/bluetooth/devices/zwift/ftms_mdns_emulator.dart b/lib/bluetooth/devices/zwift/ftms_mdns_emulator.dart index 238208b0..5cf3f03a 100644 --- a/lib/bluetooth/devices/zwift/ftms_mdns_emulator.dart +++ b/lib/bluetooth/devices/zwift/ftms_mdns_emulator.dart @@ -1,8 +1,5 @@ import 'dart:io'; -import 'package:dartx/dartx.dart'; -import 'package:flutter/foundation.dart'; -import 'package:nsd/nsd.dart'; import 'package:bike_control/bluetooth/devices/trainer_connection.dart'; import 'package:bike_control/bluetooth/devices/zwift/constants.dart'; import 'package:bike_control/bluetooth/devices/zwift/protocol/zp.pbenum.dart'; @@ -14,17 +11,22 @@ import 'package:bike_control/utils/actions/base_actions.dart'; import 'package:bike_control/utils/core.dart'; import 'package:bike_control/utils/keymap/buttons.dart'; import 'package:bike_control/utils/keymap/keymap.dart'; +import 'package:dartx/dartx.dart'; +import 'package:flutter/foundation.dart'; +import 'package:nsd/nsd.dart'; class FtmsMdnsEmulator extends TrainerConnection { ServerSocket? _tcpServer; Registration? _mdnsRegistration; + static const String connectionTitle = 'Zwift Network Emulator'; + Socket? _socket; var lastMessageId = 0; FtmsMdnsEmulator() : super( - title: 'Zwift Network Emulator', + title: connectionTitle, supportedActions: [ InGameAction.shiftUp, InGameAction.shiftDown, diff --git a/lib/bluetooth/devices/zwift/zwift_emulator.dart b/lib/bluetooth/devices/zwift/zwift_emulator.dart index f9cebb2c..958f3b4b 100644 --- a/lib/bluetooth/devices/zwift/zwift_emulator.dart +++ b/lib/bluetooth/devices/zwift/zwift_emulator.dart @@ -22,6 +22,8 @@ import 'package:permission_handler/permission_handler.dart'; class ZwiftEmulator extends TrainerConnection { bool get isLoading => _isLoading; + static const String connectionTitle = 'Zwift BLE Emulator'; + late final _peripheralManager = PeripheralManager(); bool _isLoading = false; bool _isServiceAdded = false; @@ -32,7 +34,7 @@ class ZwiftEmulator extends TrainerConnection { ZwiftEmulator() : super( - title: 'Zwift BLE Emulator', + title: connectionTitle, supportedActions: [ InGameAction.shiftUp, InGameAction.shiftDown, diff --git a/lib/bluetooth/remote_pairing.dart b/lib/bluetooth/remote_pairing.dart index 3ca61e25..286f69db 100644 --- a/lib/bluetooth/remote_pairing.dart +++ b/lib/bluetooth/remote_pairing.dart @@ -1,8 +1,5 @@ import 'dart:io'; -import 'package:bluetooth_low_energy/bluetooth_low_energy.dart'; -import 'package:flutter/foundation.dart'; -import 'package:permission_handler/permission_handler.dart'; import 'package:bike_control/bluetooth/devices/trainer_connection.dart'; import 'package:bike_control/bluetooth/devices/zwift/protocol/zp.pb.dart'; import 'package:bike_control/bluetooth/messages/notification.dart'; @@ -12,6 +9,9 @@ import 'package:bike_control/utils/actions/remote.dart'; import 'package:bike_control/utils/core.dart'; import 'package:bike_control/utils/keymap/buttons.dart'; import 'package:bike_control/utils/requirements/multi.dart'; +import 'package:bluetooth_low_energy/bluetooth_low_energy.dart'; +import 'package:flutter/foundation.dart'; +import 'package:permission_handler/permission_handler.dart'; import '../utils/keymap/keymap.dart'; @@ -26,9 +26,11 @@ class RemotePairing extends TrainerConnection { Central? _central; GATTCharacteristic? _inputReport; + static const String connectionTitle = 'Remote Control'; + RemotePairing() : super( - title: 'Remote Control', + title: connectionTitle, supportedActions: InGameAction.values, ); diff --git a/lib/i10n/intl_en.arb b/lib/i10n/intl_en.arb index 36e0ba70..323fd335 100644 --- a/lib/i10n/intl_en.arb +++ b/lib/i10n/intl_en.arb @@ -406,5 +406,7 @@ "couldNotPerformButtonnamesplitbyuppercaseNoKeymapSet": "Could not perform {button}: No keymap set", "purchase": "Purchase", "openBikeControlAnnouncement": "Great news - {trainerApp} supports the OpenBikeControl Protocol, so you'll have the best possible experience!", - "newConnectionMethodAnnouncement": "{trainerApp} will soon support much better an reliable connection methods - stay tuned for updates!" + "newConnectionMethodAnnouncement": "{trainerApp} will soon support much better, reliable connection methods - stay tuned for updates!", + "accessories": "Accessories", + "manualyControllingButton": "Control {trainerApp} manually!" } diff --git a/lib/pages/button_simulator.dart b/lib/pages/button_simulator.dart index fabca20d..14e6a53c 100644 --- a/lib/pages/button_simulator.dart +++ b/lib/pages/button_simulator.dart @@ -1,4 +1,10 @@ +import 'package:bike_control/bluetooth/devices/mywhoosh/link.dart'; +import 'package:bike_control/bluetooth/devices/openbikecontrol/obc_ble_emulator.dart'; +import 'package:bike_control/bluetooth/devices/openbikecontrol/obc_mdns_emulator.dart'; import 'package:bike_control/bluetooth/devices/trainer_connection.dart'; +import 'package:bike_control/bluetooth/devices/zwift/ftms_mdns_emulator.dart'; +import 'package:bike_control/bluetooth/devices/zwift/zwift_emulator.dart'; +import 'package:bike_control/bluetooth/remote_pairing.dart'; import 'package:bike_control/pages/touch_area.dart'; import 'package:bike_control/utils/actions/android.dart'; import 'package:bike_control/utils/actions/base_actions.dart'; @@ -7,6 +13,12 @@ import 'package:bike_control/utils/core.dart'; import 'package:bike_control/utils/i18n_extension.dart'; import 'package:bike_control/utils/keymap/buttons.dart'; import 'package:bike_control/utils/keymap/keymap.dart'; +import 'package:bike_control/widgets/apps/mywhoosh_link_tile.dart'; +import 'package:bike_control/widgets/apps/openbikecontrol_ble_tile.dart'; +import 'package:bike_control/widgets/apps/openbikecontrol_mdns_tile.dart'; +import 'package:bike_control/widgets/apps/zwift_mdns_tile.dart'; +import 'package:bike_control/widgets/apps/zwift_tile.dart'; +import 'package:bike_control/widgets/pair_widget.dart'; import 'package:bike_control/widgets/ui/gradient_text.dart'; import 'package:bike_control/widgets/ui/toast.dart'; import 'package:bike_control/widgets/ui/warning.dart'; @@ -149,7 +161,7 @@ class _ButtonSimulatorState extends State { @override Widget build(BuildContext context) { - final connectedTrainers = core.logic.connectedTrainerConnections; + final connectedTrainers = core.logic.enabledTrainerConnections; return Focus( focusNode: _focusNode, @@ -178,9 +190,27 @@ class _ButtonSimulatorState extends State { if (connectedTrainers.isEmpty) Warning( children: [ - Text('No connected trainers found. Connect a trainer to simulate button presses.'), + Text('No suitable connection method activated. Connect a trainer to simulate button presses.'), ], ), + for (final connectedTrainer in connectedTrainers) + switch (connectedTrainer.title) { + WhooshLink.connectionTitle => MyWhooshLinkTile(), + ZwiftEmulator.connectionTitle => ZwiftTile( + onUpdate: () { + setState(() {}); + }, + ), + FtmsMdnsEmulator.connectionTitle => ZwiftMdnsTile( + onUpdate: () { + setState(() {}); + }, + ), + OpenBikeControlMdnsEmulator.connectionTitle => OpenBikeControlMdnsTile(), + OpenBikeControlBluetoothEmulator.connectionTitle => OpenBikeControlBluetoothTile(), + RemotePairing.connectionTitle => RemotePairingWidget(), + _ => SizedBox.shrink(), + }, ...connectedTrainers.map( (connection) { final supportedActions = connection.supportedActions; @@ -208,30 +238,34 @@ class _ButtonSimulatorState extends State { children: group.value.map( (action) { final hotkey = _hotkeys[action]; - return PrimaryButton( - size: ButtonSize(1.6), - leading: hotkey != null - ? KeyWidget( - label: hotkey.toUpperCase(), - ) - : null, - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(action.title), - if (action.alternativeTitle != null) - Text( - action.alternativeTitle!, - style: TextStyle(fontSize: 12, color: Colors.gray), - ), - ], - ), - onPressed: () {}, - onTapDown: (c) async { - _sendKey(context, down: true, action: action, connection: connection); - }, - onTapUp: (c) async { - _sendKey(context, down: false, action: action, connection: connection); + return Builder( + builder: (context) { + return PrimaryButton( + size: ButtonSize(1.6), + leading: hotkey != null + ? KeyWidget( + label: hotkey.toUpperCase(), + ) + : null, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(action.title), + if (action.alternativeTitle != null) + Text( + action.alternativeTitle!, + style: TextStyle(fontSize: 12, color: Colors.gray), + ), + ], + ), + onPressed: () {}, + onTapDown: (c) async { + _sendKey(context, down: true, action: action, connection: connection); + }, + onTapUp: (c) async { + _sendKey(context, down: false, action: action, connection: connection); + }, + ); }, ); }, diff --git a/lib/pages/device.dart b/lib/pages/device.dart index 379943d8..02b7d860 100644 --- a/lib/pages/device.dart +++ b/lib/pages/device.dart @@ -1,17 +1,13 @@ import 'dart:async'; -import 'package:bike_control/bluetooth/devices/zwift/protocol/zp.pb.dart'; +import 'package:bike_control/gen/l10n.dart'; import 'package:bike_control/main.dart'; -import 'package:bike_control/pages/button_simulator.dart'; import 'package:bike_control/utils/core.dart'; import 'package:bike_control/utils/i18n_extension.dart'; import 'package:bike_control/utils/iap/iap_manager.dart'; import 'package:bike_control/widgets/iap_status_widget.dart'; import 'package:bike_control/widgets/scan.dart'; import 'package:bike_control/widgets/ui/colored_title.dart'; -import 'package:bike_control/widgets/ui/toast.dart'; -import 'package:dartx/dartx.dart'; -import 'package:flutter/foundation.dart'; import 'package:shadcn_flutter/shadcn_flutter.dart'; import '../bluetooth/devices/base_device.dart'; @@ -56,16 +52,22 @@ class _DevicePageState extends State with WidgetsBindingObserver { valueListenable: IAPManager.instance.isPurchased, builder: (context, value, child) => value ? SizedBox.shrink() : IAPStatusWidget(small: false), ), - Padding( - padding: const EdgeInsets.only(top: 8.0), - child: ColoredTitle( - text: core.connection.controllerDevices.isEmpty - ? context.i18n.connectControllers - : context.i18n.connectedControllers, - ), - ), - if (core.connection.controllerDevices.isEmpty || kIsWeb) ScanWidget(), + if (core.connection.controllerDevices.isEmpty) + Padding( + padding: const EdgeInsets.only(top: 8.0), + child: ColoredTitle(text: context.i18n.connectControllers), + ), + + // leave it in for the extra scanning options + ScanWidget(), + + if (core.connection.controllerDevices.isNotEmpty) + Padding( + padding: const EdgeInsets.only(top: 8.0), + child: ColoredTitle(text: context.i18n.connectedControllers), + ), + ...core.connection.controllerDevices.map( (device) => Card( filled: true, @@ -79,9 +81,7 @@ class _DevicePageState extends State with WidgetsBindingObserver { if (core.connection.accessories.isNotEmpty) ...[ Padding( padding: const EdgeInsets.only(top: 8.0), - child: ColoredTitle( - text: 'Accessories', - ), + child: ColoredTitle(text: AppLocalizations.of(context).accessories), ), ...core.connection.accessories.map( (device) => Card( @@ -109,7 +109,8 @@ class _DevicePageState extends State with WidgetsBindingObserver { SizedBox(), if (core.connection.controllerDevices.isNotEmpty) Row( - mainAxisAlignment: MainAxisAlignment.end, + spacing: 8, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ PrimaryButton( child: Text(context.i18n.connectToTrainerApp), @@ -118,37 +119,6 @@ class _DevicePageState extends State with WidgetsBindingObserver { }, ), ], - ) - else - PrimaryButton( - child: Text( - 'No Controller? Control ${core.settings.getTrainerApp()?.name ?? 'your trainer'} manually!', - ), - onPressed: () { - if (core.settings.getTrainerApp() == null) { - buildToast( - context, - level: LogLevel.LOGLEVEL_WARNING, - title: context.i18n.selectTrainerApp, - ); - widget.onUpdate(); - } else if (core.logic.connectedTrainerConnections.isEmpty) { - buildToast( - context, - level: LogLevel.LOGLEVEL_WARNING, - title: - 'Please connect to ${core.settings.getTrainerApp()?.name ?? 'your trainer'} with ${core.logic.trainerConnections.joinToString(transform: (t) => t.title, separator: ' or ')}, first.', - ); - widget.onUpdate(); - } else { - Navigator.push( - context, - MaterialPageRoute( - builder: (c) => ButtonSimulator(), - ), - ); - } - }, ), ], ), diff --git a/lib/pages/trainer.dart b/lib/pages/trainer.dart index 53c0f24c..cde407a5 100644 --- a/lib/pages/trainer.dart +++ b/lib/pages/trainer.dart @@ -1,6 +1,7 @@ import 'package:bike_control/bluetooth/messages/notification.dart'; import 'package:bike_control/gen/l10n.dart'; import 'package:bike_control/main.dart'; +import 'package:bike_control/pages/button_simulator.dart'; import 'package:bike_control/pages/configuration.dart'; import 'package:bike_control/utils/core.dart'; import 'package:bike_control/utils/i18n_extension.dart'; @@ -21,6 +22,8 @@ import 'package:shadcn_flutter/shadcn_flutter.dart'; import 'package:universal_ble/universal_ble.dart'; import 'package:wakelock_plus/wakelock_plus.dart'; +import '../bluetooth/devices/zwift/protocol/zp.pbenum.dart'; + class TrainerPage extends StatefulWidget { final VoidCallback onUpdate; final VoidCallback goToNextPage; @@ -166,8 +169,32 @@ class _TrainerPageState extends State with WidgetsBindingObserver { SizedBox(), Row( - mainAxisAlignment: MainAxisAlignment.end, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + PrimaryButton( + child: Text( + AppLocalizations.of( + context, + ).manualyControllingButton(core.settings.getTrainerApp()?.name ?? 'your trainer'), + ), + onPressed: () { + if (core.settings.getTrainerApp() == null) { + buildToast( + context, + level: LogLevel.LOGLEVEL_WARNING, + title: context.i18n.selectTrainerApp, + ); + widget.onUpdate(); + } else { + Navigator.push( + context, + MaterialPageRoute( + builder: (c) => ButtonSimulator(), + ), + ); + } + }, + ), PrimaryButton( child: Text(context.i18n.adjustControllerButtons), onPressed: () { diff --git a/lib/utils/core.dart b/lib/utils/core.dart index 09b639d8..ae914633 100644 --- a/lib/utils/core.dart +++ b/lib/utils/core.dart @@ -235,6 +235,15 @@ class CoreLogic { if (isRemoteControlEnabled) core.remotePairing, ].filter((e) => e.isConnected.value).toList(); + List get enabledTrainerConnections => [ + if (isMyWhooshLinkEnabled) core.whooshLink, + if (isObpMdnsEnabled) core.obpMdnsEmulator, + if (isObpBleEnabled) core.obpBluetoothEmulator, + if (isZwiftBleEnabled) core.zwiftEmulator, + if (isZwiftMdnsEnabled) core.zwiftMdnsEmulator, + if (isRemoteControlEnabled) core.remotePairing, + ]; + List get trainerConnections => [ if (showMyWhooshLink) core.whooshLink, if (showObpMdnsEmulator) core.obpMdnsEmulator, From 6b5f37e92d91e337f07bba39fa8ad550cb0ce616 Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Thu, 18 Dec 2025 08:46:31 +0100 Subject: [PATCH 3/5] auto-open key editor on key press --- lib/pages/button_edit.dart | 189 ++++++++++++++++------------ lib/pages/configuration.dart | 1 + lib/pages/customize.dart | 16 +-- lib/widgets/keymap_explanation.dart | 80 +++++++----- 4 files changed, 165 insertions(+), 121 deletions(-) diff --git a/lib/pages/button_edit.dart b/lib/pages/button_edit.dart index 254ea6e8..a7f77f29 100644 --- a/lib/pages/button_edit.dart +++ b/lib/pages/button_edit.dart @@ -1,3 +1,6 @@ +import 'dart:async'; + +import 'package:bike_control/bluetooth/messages/notification.dart'; import 'package:bike_control/gen/l10n.dart'; import 'package:bike_control/pages/touch_area.dart'; import 'package:bike_control/utils/actions/android.dart'; @@ -17,26 +20,52 @@ import 'package:flutter/services.dart'; import 'package:shadcn_flutter/shadcn_flutter.dart'; class ButtonEditPage extends StatefulWidget { + final Keymap keymap; final KeyPair keyPair; final VoidCallback onUpdate; - const ButtonEditPage({super.key, required this.keyPair, required this.onUpdate}); + const ButtonEditPage({super.key, required this.keyPair, required this.onUpdate, required this.keymap}); @override State createState() => _ButtonEditPageState(); } class _ButtonEditPageState extends State { + late KeyPair _keyPair; late final ScrollController _scrollController = ScrollController(); + late StreamSubscription _actionSubscription; + + @override + void initState() { + super.initState(); + _keyPair = widget.keyPair; + _actionSubscription = core.connection.actionStream.listen((data) async { + if (!mounted) { + return; + } + if (data is ButtonNotification && data.buttonsClicked.length == 1) { + final clickedButton = data.buttonsClicked.first; + final keyPair = widget.keymap.keyPairs.firstOrNullWhere( + (kp) => kp.buttons.contains(clickedButton), + ); + if (keyPair != null) { + setState(() { + _keyPair = keyPair; + }); + } + } + }); + } + @override void dispose() { _scrollController.dispose(); + _actionSubscription.cancel(); super.dispose(); } @override Widget build(BuildContext context) { - final keyPair = widget.keyPair; final trainerApp = core.settings.getTrainerApp(); final actionsWithInGameAction = trainerApp?.keymap.keyPairs @@ -64,7 +93,7 @@ class _ButtonEditPageState extends State { spacing: 8, children: [ Text('Editing').h3, - ButtonWidget(button: widget.keyPair.buttons.first), + ButtonWidget(button: _keyPair.buttons.first), Expanded(child: SizedBox()), IconButton( icon: Icon(Icons.close), @@ -88,13 +117,13 @@ class _ButtonEditPageState extends State { ColoredTitle(text: context.i18n.openBikeControlActions), Builder( builder: (context) => SelectableCard( - icon: keyPair.inGameAction?.icon ?? Icons.link, + icon: _keyPair.inGameAction?.icon ?? Icons.link, title: Text( core.logic.obpConnectedApp == null ? 'Please connect to ${core.settings.getTrainerApp()?.name}, first.' : context.i18n.appIdActions(core.logic.obpConnectedApp!.appId), ), - isActive: core.logic.obpConnectedApp != null && keyPair.inGameAction != null, + isActive: core.logic.obpConnectedApp != null && _keyPair.inGameAction != null, onPressed: core.logic.obpConnectedApp == null ? null : () { @@ -105,11 +134,11 @@ class _ButtonEditPageState extends State { (action) => MenuButton( leading: action.icon != null ? Icon(action.icon) : null, onPressed: (_) { - keyPair.touchPosition = Offset.zero; - keyPair.physicalKey = null; - keyPair.logicalKey = null; - keyPair.inGameAction = action; - keyPair.inGameActionValue = null; + _keyPair.touchPosition = Offset.zero; + _keyPair.physicalKey = null; + _keyPair.logicalKey = null; + _keyPair.inGameAction = action; + _keyPair.inGameActionValue = null; widget.onUpdate(); setState(() {}); }, @@ -130,12 +159,12 @@ class _ButtonEditPageState extends State { ColoredTitle(text: context.i18n.myWhooshDirectConnectAction), Builder( builder: (context) => SelectableCard( - icon: keyPair.inGameAction?.icon ?? Icons.link, + icon: _keyPair.inGameAction?.icon ?? Icons.link, title: Text(context.i18n.myWhooshDirectConnectAction), isActive: - keyPair.inGameAction != null && - core.whooshLink.supportedActions.contains(keyPair.inGameAction), - value: [keyPair.inGameAction.toString(), ?keyPair.inGameActionValue?.toString()].join(' '), + _keyPair.inGameAction != null && + core.whooshLink.supportedActions.contains(_keyPair.inGameAction), + value: [_keyPair.inGameAction.toString(), ?_keyPair.inGameActionValue?.toString()].join(' '), onPressed: () { showDropdown( context: context, @@ -148,8 +177,8 @@ class _ButtonEditPageState extends State { (value) => MenuButton( child: Text(value.toString()), onPressed: (_) { - keyPair.inGameAction = ingame; - keyPair.inGameActionValue = value; + _keyPair.inGameAction = ingame; + _keyPair.inGameActionValue = value; widget.onUpdate(); setState(() {}); }, @@ -159,8 +188,8 @@ class _ButtonEditPageState extends State { leading: ingame.icon != null ? Icon(ingame.icon) : null, child: Text(ingame.toString()), onPressed: (_) { - keyPair.inGameAction = ingame; - keyPair.inGameActionValue = null; + _keyPair.inGameAction = ingame; + _keyPair.inGameActionValue = null; widget.onUpdate(); setState(() {}); }, @@ -178,12 +207,12 @@ class _ButtonEditPageState extends State { ColoredTitle(text: context.i18n.zwiftControllerAction), Builder( builder: (context) => SelectableCard( - icon: keyPair.inGameAction?.icon ?? Icons.link, + icon: _keyPair.inGameAction?.icon ?? Icons.link, title: Text(context.i18n.zwiftControllerAction), isActive: - keyPair.inGameAction != null && - core.zwiftEmulator.supportedActions.contains(keyPair.inGameAction), - value: [keyPair.inGameAction.toString(), ?keyPair.inGameActionValue?.toString()].join(' '), + _keyPair.inGameAction != null && + core.zwiftEmulator.supportedActions.contains(_keyPair.inGameAction), + value: [_keyPair.inGameAction.toString(), ?_keyPair.inGameActionValue?.toString()].join(' '), onPressed: () { showDropdown( context: context, @@ -196,8 +225,8 @@ class _ButtonEditPageState extends State { (value) => MenuButton( child: Text(value.toString()), onPressed: (_) { - keyPair.inGameAction = ingame; - keyPair.inGameActionValue = value; + _keyPair.inGameAction = ingame; + _keyPair.inGameActionValue = value; widget.onUpdate(); setState(() {}); }, @@ -206,8 +235,8 @@ class _ButtonEditPageState extends State { .toList(), leading: ingame.icon != null ? Icon(ingame.icon) : null, onPressed: (_) { - keyPair.inGameAction = ingame; - keyPair.inGameActionValue = null; + _keyPair.inGameAction = ingame; + _keyPair.inGameActionValue = null; widget.onUpdate(); setState(() {}); }, @@ -243,22 +272,22 @@ class _ButtonEditPageState extends State { onPressed: (_) { // Copy all properties from the selected predefined action if (core.actionHandler.supportedModes.contains(SupportedMode.keyboard)) { - keyPair.physicalKey = keyPairAction.physicalKey; - keyPair.logicalKey = keyPairAction.logicalKey; - keyPair.modifiers = List.of(keyPairAction.modifiers); + _keyPair.physicalKey = keyPairAction.physicalKey; + _keyPair.logicalKey = keyPairAction.logicalKey; + _keyPair.modifiers = List.of(keyPairAction.modifiers); } else { - keyPair.physicalKey = null; - keyPair.logicalKey = null; - keyPair.modifiers = []; + _keyPair.physicalKey = null; + _keyPair.logicalKey = null; + _keyPair.modifiers = []; } if (core.actionHandler.supportedModes.contains(SupportedMode.touch)) { - keyPair.touchPosition = keyPairAction.touchPosition; + _keyPair.touchPosition = keyPairAction.touchPosition; } else { - keyPair.touchPosition = Offset.zero; + _keyPair.touchPosition = Offset.zero; } - keyPair.isLongPress = keyPairAction.isLongPress; - keyPair.inGameAction = keyPairAction.inGameAction; - keyPair.inGameActionValue = keyPairAction.inGameActionValue; + _keyPair.isLongPress = keyPairAction.isLongPress; + _keyPair.inGameAction = keyPairAction.inGameAction; + _keyPair.inGameActionValue = keyPairAction.inGameActionValue; setState(() {}); }, child: Text(keyPairAction.toString()), @@ -274,15 +303,15 @@ class _ButtonEditPageState extends State { SelectableCard( icon: RadixIcons.keyboard, title: Text(context.i18n.simulateKeyboardShortcut), - isActive: keyPair.physicalKey != null && !keyPair.isSpecialKey, - value: keyPair.toString(), + isActive: _keyPair.physicalKey != null && !_keyPair.isSpecialKey, + value: _keyPair.toString(), onPressed: () async { await showDialog( context: context, barrierDismissible: false, // enable Escape key builder: (c) => HotKeyListenerDialog( customApp: core.actionHandler.supportedApp! as CustomApp, - keyPair: keyPair, + keyPair: _keyPair, ), ); setState(() {}); @@ -293,18 +322,18 @@ class _ButtonEditPageState extends State { SelectableCard( title: Text(context.i18n.simulateTouch), icon: core.actionHandler is AndroidActions ? Icons.touch_app_outlined : BootstrapIcons.mouse, - isActive: keyPair.physicalKey == null && keyPair.touchPosition != Offset.zero, - value: keyPair.toString(), + isActive: _keyPair.physicalKey == null && _keyPair.touchPosition != Offset.zero, + value: _keyPair.toString(), onPressed: () async { - if (keyPair.touchPosition == Offset.zero) { - keyPair.touchPosition = Offset(50, 50); + if (_keyPair.touchPosition == Offset.zero) { + _keyPair.touchPosition = Offset(50, 50); } - keyPair.physicalKey = null; - keyPair.logicalKey = null; + _keyPair.physicalKey = null; + _keyPair.logicalKey = null; await Navigator.of(context).push( MaterialPageRoute( builder: (c) => TouchAreaSetupPage( - keyPair: keyPair, + keyPair: _keyPair, ), ), ); @@ -317,9 +346,9 @@ class _ButtonEditPageState extends State { Builder( builder: (context) => SelectableCard( icon: Icons.music_note_outlined, - isActive: keyPair.isSpecialKey, + isActive: _keyPair.isSpecialKey, title: Text(context.i18n.simulateMediaKey), - value: keyPair.toString(), + value: _keyPair.toString(), onPressed: () { showDropdown( context: context, @@ -328,8 +357,8 @@ class _ButtonEditPageState extends State { MenuButton( child: Text(context.i18n.playPause), onPressed: (c) { - keyPair.physicalKey = PhysicalKeyboardKey.mediaPlayPause; - keyPair.logicalKey = null; + _keyPair.physicalKey = PhysicalKeyboardKey.mediaPlayPause; + _keyPair.logicalKey = null; setState(() {}); widget.onUpdate(); @@ -338,8 +367,8 @@ class _ButtonEditPageState extends State { MenuButton( child: Text(context.i18n.stop), onPressed: (c) { - keyPair.physicalKey = PhysicalKeyboardKey.mediaStop; - keyPair.logicalKey = null; + _keyPair.physicalKey = PhysicalKeyboardKey.mediaStop; + _keyPair.logicalKey = null; setState(() {}); widget.onUpdate(); @@ -349,8 +378,8 @@ class _ButtonEditPageState extends State { child: Text(context.i18n.previous), onPressed: (c) { - keyPair.physicalKey = PhysicalKeyboardKey.mediaTrackPrevious; - keyPair.logicalKey = null; + _keyPair.physicalKey = PhysicalKeyboardKey.mediaTrackPrevious; + _keyPair.logicalKey = null; setState(() {}); widget.onUpdate(); @@ -359,8 +388,8 @@ class _ButtonEditPageState extends State { MenuButton( child: Text(context.i18n.next), onPressed: (c) { - keyPair.physicalKey = PhysicalKeyboardKey.mediaTrackNext; - keyPair.logicalKey = null; + _keyPair.physicalKey = PhysicalKeyboardKey.mediaTrackNext; + _keyPair.logicalKey = null; setState(() {}); widget.onUpdate(); @@ -368,8 +397,8 @@ class _ButtonEditPageState extends State { ), MenuButton( onPressed: (c) { - keyPair.physicalKey = PhysicalKeyboardKey.audioVolumeUp; - keyPair.logicalKey = null; + _keyPair.physicalKey = PhysicalKeyboardKey.audioVolumeUp; + _keyPair.logicalKey = null; setState(() {}); widget.onUpdate(); @@ -379,8 +408,8 @@ class _ButtonEditPageState extends State { MenuButton( child: Text(context.i18n.volumeDown), onPressed: (c) { - keyPair.physicalKey = PhysicalKeyboardKey.audioVolumeDown; - keyPair.logicalKey = null; + _keyPair.physicalKey = PhysicalKeyboardKey.audioVolumeDown; + _keyPair.logicalKey = null; setState(() {}); widget.onUpdate(); @@ -402,11 +431,11 @@ class _ButtonEditPageState extends State { icon: Icons.air, title: Text('KICKR Headwind'), isActive: - keyPair.inGameAction != null && - (keyPair.inGameAction == InGameAction.headwindSpeed || - keyPair.inGameAction == InGameAction.headwindHeartRateMode), - value: keyPair.inGameAction != null - ? '${keyPair.inGameAction} ${keyPair.inGameActionValue ?? ""}'.trim() + _keyPair.inGameAction != null && + (_keyPair.inGameAction == InGameAction.headwindSpeed || + _keyPair.inGameAction == InGameAction.headwindHeartRateMode), + value: _keyPair.inGameAction != null + ? '${_keyPair.inGameAction} ${_keyPair.inGameActionValue ?? ""}'.trim() : null, onPressed: () { showDropdown( @@ -419,8 +448,8 @@ class _ButtonEditPageState extends State { (value) => MenuButton( child: Text('Set Speed to $value%'), onPressed: (_) { - keyPair.inGameAction = InGameAction.headwindSpeed; - keyPair.inGameActionValue = value; + _keyPair.inGameAction = InGameAction.headwindSpeed; + _keyPair.inGameActionValue = value; widget.onUpdate(); setState(() {}); }, @@ -432,8 +461,8 @@ class _ButtonEditPageState extends State { MenuButton( child: Text('Set to Heart Rate Mode'), onPressed: (_) { - keyPair.inGameAction = InGameAction.headwindHeartRateMode; - keyPair.inGameActionValue = null; + _keyPair.inGameAction = InGameAction.headwindHeartRateMode; + _keyPair.inGameActionValue = null; widget.onUpdate(); setState(() {}); }, @@ -449,11 +478,11 @@ class _ButtonEditPageState extends State { SizedBox(height: 8), ColoredTitle(text: context.i18n.setting), SelectableCard( - icon: keyPair.isLongPress ? Icons.check_box : Icons.check_box_outline_blank, + icon: _keyPair.isLongPress ? Icons.check_box : Icons.check_box_outline_blank, title: Text(context.i18n.longPressMode), - isActive: keyPair.isLongPress, + isActive: _keyPair.isLongPress, onPressed: () { - keyPair.isLongPress = !keyPair.isLongPress; + _keyPair.isLongPress = !_keyPair.isLongPress; widget.onUpdate(); setState(() {}); }, @@ -461,13 +490,13 @@ class _ButtonEditPageState extends State { SizedBox(height: 8), DestructiveButton( onPressed: () { - keyPair.isLongPress = false; - keyPair.physicalKey = null; - keyPair.logicalKey = null; - keyPair.modifiers = []; - keyPair.touchPosition = Offset.zero; - keyPair.inGameAction = null; - keyPair.inGameActionValue = null; + _keyPair.isLongPress = false; + _keyPair.physicalKey = null; + _keyPair.logicalKey = null; + _keyPair.modifiers = []; + _keyPair.touchPosition = Offset.zero; + _keyPair.inGameAction = null; + _keyPair.inGameActionValue = null; widget.onUpdate(); setState(() {}); }, diff --git a/lib/pages/configuration.dart b/lib/pages/configuration.dart index 3d3252e2..1b306df0 100644 --- a/lib/pages/configuration.dart +++ b/lib/pages/configuration.dart @@ -1,3 +1,4 @@ +import 'dart:async'; import 'dart:io'; import 'package:bike_control/gen/l10n.dart'; diff --git a/lib/pages/customize.dart b/lib/pages/customize.dart index eb359f12..c81dc323 100644 --- a/lib/pages/customize.dart +++ b/lib/pages/customize.dart @@ -1,4 +1,3 @@ -import 'package:bike_control/bluetooth/devices/zwift/zwift_device.dart'; import 'package:bike_control/main.dart'; import 'package:bike_control/utils/core.dart'; import 'package:bike_control/utils/i18n_extension.dart'; @@ -23,10 +22,6 @@ class CustomizePage extends StatefulWidget { class _CustomizeState extends State { @override Widget build(BuildContext context) { - final canVibrate = core.connection.bluetoothDevices.any( - (device) => device.isConnected && device is ZwiftDevice && device.canVibrate, - ); - return SingleChildScrollView( padding: EdgeInsets.all(16), child: Column( @@ -62,7 +57,10 @@ class _CustomizeState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Expanded(child: Text(a.name)), - if (a is CustomApp) BetaPill(text: 'CUSTOM'), + if (a is CustomApp) + BetaPill(text: 'CUSTOM') + else if (a.supportsOpenBikeProtocol) + Icon(Icons.star, size: 16), ], ), ), @@ -88,12 +86,6 @@ class _CustomizeState extends State { if (app is CustomApp) BetaPill(text: 'CUSTOM'), ], ), - /*DropdownMenuEntry( - value: CustomApp(profileName: 'New'), - label: 'Create new keymap', - labelWidget: Text('Create new keymap'), - leadingIcon: Icon(Icons.add), - ),*/ placeholder: Text(context.i18n.selectKeymap), onChanged: (app) async { diff --git a/lib/widgets/keymap_explanation.dart b/lib/widgets/keymap_explanation.dart index 0dde771d..e968384a 100644 --- a/lib/widgets/keymap_explanation.dart +++ b/lib/widgets/keymap_explanation.dart @@ -12,6 +12,7 @@ import 'package:bike_control/widgets/ui/toast.dart'; import 'package:dartx/dartx.dart'; import 'package:shadcn_flutter/shadcn_flutter.dart'; +import '../bluetooth/messages/notification.dart'; import '../pages/touch_area.dart'; class KeymapExplanation extends StatefulWidget { @@ -26,12 +27,37 @@ class KeymapExplanation extends StatefulWidget { class _KeymapExplanationState extends State { late StreamSubscription _updateStreamListener; + late StreamSubscription _actionSubscription; + + bool _isDrawerOpen = false; + @override void initState() { super.initState(); _updateStreamListener = widget.keymap.updateStream.listen((_) { setState(() {}); }); + _actionSubscription = core.connection.actionStream.listen((data) async { + if (!mounted) { + return; + } + if (data is ButtonNotification && data.buttonsClicked.length == 1) { + final clickedButton = data.buttonsClicked.first; + final keyPair = widget.keymap.keyPairs.firstOrNullWhere( + (kp) => kp.buttons.contains(clickedButton), + ); + if (keyPair != null && !_isDrawerOpen) { + await _openKeyPairEditor(keyPair); + } + } + }); + } + + @override + void dispose() { + super.dispose(); + _updateStreamListener.cancel(); + _actionSubscription.cancel(); } @override @@ -45,12 +71,6 @@ class _KeymapExplanationState extends State { } } - @override - void dispose() { - super.dispose(); - _updateStreamListener.cancel(); - } - @override Widget build(BuildContext context) { final allAvailableButtons = IterableFlatMap(core.connection.devices).flatMap((d) => d.availableButtons); @@ -64,6 +84,12 @@ class _KeymapExplanationState extends State { crossAxisAlignment: CrossAxisAlignment.stretch, spacing: 8, children: [ + if (core.connection.controllerDevices.isNotEmpty) + Text( + 'Click a button on your controller to edit its action or tap the edit icon.', + style: TextStyle(fontSize: 12), + ).muted, + for (final keyPair in availableKeypairs) ...[ Button.card( style: ButtonStyle.card().withBackgroundColor(color: Theme.of(context).colorScheme.background), @@ -80,31 +106,10 @@ class _KeymapExplanationState extends State { final selectedKeyPair = core.actionHandler.supportedApp!.keymap.keyPairs.firstWhere( (e) => e == keyPair, ); - await openDrawer( - context: context, - builder: (c) => ButtonEditPage( - keyPair: selectedKeyPair, - onUpdate: () { - widget.onUpdate(); - }, - ), - position: OverlayPosition.end, - ); + _openKeyPairEditor(selectedKeyPair); } - widget.onUpdate(); } else { - await openDrawer( - context: context, - - builder: (c) => ButtonEditPage( - keyPair: keyPair, - onUpdate: () { - widget.onUpdate(); - }, - ), - position: OverlayPosition.end, - ); - widget.onUpdate(); + _openKeyPairEditor(keyPair); } }, child: Row( @@ -158,6 +163,23 @@ class _KeymapExplanationState extends State { ], ); } + + Future _openKeyPairEditor(KeyPair selectedKeyPair) async { + _isDrawerOpen = true; + await openDrawer( + context: context, + builder: (c) => ButtonEditPage( + keyPair: selectedKeyPair, + keymap: widget.keymap, + onUpdate: () { + widget.onUpdate(); + }, + ), + position: OverlayPosition.end, + ); + widget.onUpdate(); + _isDrawerOpen = false; + } } extension SplitByUppercase on String { From de31f84e378004b46f59318d234a514210dd9eb1 Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Thu, 18 Dec 2025 09:26:25 +0100 Subject: [PATCH 4/5] bugfix and animation --- lib/bluetooth/connection.dart | 17 +-- lib/pages/button_edit.dart | 217 ++++++++++++---------------- lib/pages/customize.dart | 3 +- lib/utils/actions/base_actions.dart | 19 +-- lib/utils/keymap/buttons.dart | 4 +- lib/utils/keymap/keymap.dart | 15 ++ 6 files changed, 112 insertions(+), 163 deletions(-) diff --git a/lib/bluetooth/connection.dart b/lib/bluetooth/connection.dart index ffcf29d5..0b9d218d 100644 --- a/lib/bluetooth/connection.dart +++ b/lib/bluetooth/connection.dart @@ -11,13 +11,11 @@ import 'package:bike_control/gen/l10n.dart'; import 'package:bike_control/main.dart'; import 'package:bike_control/utils/actions/android.dart'; import 'package:bike_control/utils/core.dart'; -import 'package:bike_control/utils/keymap/keymap.dart'; import 'package:bike_control/utils/requirements/android.dart'; 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:shadcn_flutter/shadcn_flutter.dart'; import 'package:universal_ble/universal_ble.dart'; import 'devices/base_device.dart'; @@ -312,20 +310,7 @@ class Connection { await device.connect(); signalChange(device); - final newButtons = device.availableButtons.filter( - (button) => core.actionHandler.supportedApp?.keymap.getKeyPair(button) == null, - ); - for (final button in newButtons) { - core.actionHandler.supportedApp?.keymap.addKeyPair( - KeyPair( - touchPosition: Offset.zero, - buttons: [button], - physicalKey: null, - logicalKey: null, - isLongPress: false, - ), - ); - } + core.actionHandler.supportedApp?.keymap.addNewButtons(device.availableButtons); _streamSubscriptions[device] = actionSubscription; } catch (e, backtrace) { diff --git a/lib/pages/button_edit.dart b/lib/pages/button_edit.dart index a7f77f29..227ff6ab 100644 --- a/lib/pages/button_edit.dart +++ b/lib/pages/button_edit.dart @@ -32,6 +32,22 @@ class ButtonEditPage extends StatefulWidget { class _ButtonEditPageState extends State { late KeyPair _keyPair; late final ScrollController _scrollController = ScrollController(); + final double baseHeight = 46; + bool _bumped = false; + + void _triggerBump() async { + setState(() { + _bumped = true; + }); + + await Future.delayed(const Duration(milliseconds: 150)); + + if (mounted) { + setState(() { + _bumped = false; + }); + } + } late StreamSubscription _actionSubscription; @@ -52,6 +68,7 @@ class _ButtonEditPageState extends State { setState(() { _keyPair = keyPair; }); + _triggerBump(); } } }); @@ -83,7 +100,7 @@ class _ButtonEditPageState extends State { padding: const EdgeInsets.only(right: 26.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, - spacing: 16, + spacing: 8, children: [ SizedBox(height: 16), Row( @@ -93,7 +110,14 @@ class _ButtonEditPageState extends State { spacing: 8, children: [ Text('Editing').h3, - ButtonWidget(button: _keyPair.buttons.first), + AnimatedContainer( + duration: const Duration(milliseconds: 600), + curve: Curves.easeOut, + width: _keyPair.buttons.first.color != null ? baseHeight : null, + height: _keyPair.buttons.first.color != null ? baseHeight : null, + padding: EdgeInsets.all(_bumped ? 0 : 6.0), + child: ButtonWidget(button: _keyPair.buttons.first), + ), Expanded(child: SizedBox()), IconButton( icon: Icon(Icons.close), @@ -115,140 +139,29 @@ class _ButtonEditPageState extends State { ), if (core.logic.showObpActions) ...[ ColoredTitle(text: context.i18n.openBikeControlActions), - Builder( - builder: (context) => SelectableCard( - icon: _keyPair.inGameAction?.icon ?? Icons.link, - title: Text( - core.logic.obpConnectedApp == null - ? 'Please connect to ${core.settings.getTrainerApp()?.name}, first.' - : context.i18n.appIdActions(core.logic.obpConnectedApp!.appId), - ), - isActive: core.logic.obpConnectedApp != null && _keyPair.inGameAction != null, - onPressed: core.logic.obpConnectedApp == null - ? null - : () { - showDropdown( - builder: (c) => DropdownMenu( - children: core.logic.obpConnectedApp!.supportedActions - .map( - (action) => MenuButton( - leading: action.icon != null ? Icon(action.icon) : null, - onPressed: (_) { - _keyPair.touchPosition = Offset.zero; - _keyPair.physicalKey = null; - _keyPair.logicalKey = null; - _keyPair.inGameAction = action; - _keyPair.inGameActionValue = null; - widget.onUpdate(); - setState(() {}); - }, - child: Text(action.name), - ), - ) - .toList(), - ), - context: context, - ); - }, - ), - ), + if (core.logic.obpConnectedApp == null) + Warning( + children: [ + Text( + core.logic.obpConnectedApp == null + ? 'Please connect to ${core.settings.getTrainerApp()?.name}, first.' + : context.i18n.appIdActions(core.logic.obpConnectedApp!.appId), + ), + ], + ) + else + ..._buildTrainerConnectionActions(core.logic.obpConnectedApp!.supportedActions), ], if (core.settings.getMyWhooshLinkEnabled() && core.logic.showMyWhooshLink) ...[ SizedBox(height: 8), ColoredTitle(text: context.i18n.myWhooshDirectConnectAction), - Builder( - builder: (context) => SelectableCard( - icon: _keyPair.inGameAction?.icon ?? Icons.link, - title: Text(context.i18n.myWhooshDirectConnectAction), - isActive: - _keyPair.inGameAction != null && - core.whooshLink.supportedActions.contains(_keyPair.inGameAction), - value: [_keyPair.inGameAction.toString(), ?_keyPair.inGameActionValue?.toString()].join(' '), - onPressed: () { - showDropdown( - context: context, - builder: (c) => DropdownMenu( - children: core.whooshLink.supportedActions.map( - (ingame) { - return MenuButton( - subMenu: ingame.possibleValues - ?.map( - (value) => MenuButton( - child: Text(value.toString()), - onPressed: (_) { - _keyPair.inGameAction = ingame; - _keyPair.inGameActionValue = value; - widget.onUpdate(); - setState(() {}); - }, - ), - ) - .toList(), - leading: ingame.icon != null ? Icon(ingame.icon) : null, - child: Text(ingame.toString()), - onPressed: (_) { - _keyPair.inGameAction = ingame; - _keyPair.inGameActionValue = null; - widget.onUpdate(); - setState(() {}); - }, - ); - }, - ).toList(), - ), - ); - }, - ), - ), + ..._buildTrainerConnectionActions(core.whooshLink.supportedActions), ], if (core.logic.isZwiftBleEnabled || core.logic.isZwiftMdnsEnabled) ...[ SizedBox(height: 8), ColoredTitle(text: context.i18n.zwiftControllerAction), - Builder( - builder: (context) => SelectableCard( - icon: _keyPair.inGameAction?.icon ?? Icons.link, - title: Text(context.i18n.zwiftControllerAction), - isActive: - _keyPair.inGameAction != null && - core.zwiftEmulator.supportedActions.contains(_keyPair.inGameAction), - value: [_keyPair.inGameAction.toString(), ?_keyPair.inGameActionValue?.toString()].join(' '), - onPressed: () { - showDropdown( - context: context, - builder: (c) => DropdownMenu( - children: core.zwiftEmulator.supportedActions.map( - (ingame) { - return MenuButton( - subMenu: ingame.possibleValues - ?.map( - (value) => MenuButton( - child: Text(value.toString()), - onPressed: (_) { - _keyPair.inGameAction = ingame; - _keyPair.inGameActionValue = value; - widget.onUpdate(); - setState(() {}); - }, - ), - ) - .toList(), - leading: ingame.icon != null ? Icon(ingame.icon) : null, - onPressed: (_) { - _keyPair.inGameAction = ingame; - _keyPair.inGameActionValue = null; - widget.onUpdate(); - setState(() {}); - }, - child: Text(ingame.toString()), - ); - }, - ).toList(), - ), - ); - }, - ), - ), + ..._buildTrainerConnectionActions(core.zwiftEmulator.supportedActions), ], if (core.logic.showLocalRemoteOptions) ...[ @@ -510,6 +423,56 @@ class _ButtonEditPageState extends State { ), ); } + + List _buildTrainerConnectionActions(List supportedActions) { + return supportedActions.map((action) { + return Builder( + builder: (context) { + return SelectableCard( + icon: action.icon, + title: Text(action.title), + subtitle: (action.possibleValues != null && action == _keyPair.inGameAction) + ? Text(_keyPair.inGameActionValue!.toString()) + : null, + isActive: _keyPair.inGameAction == action && supportedActions.contains(_keyPair.inGameAction), + onPressed: () { + if (action.possibleValues?.isNotEmpty == true) { + showDropdown( + context: context, + builder: (c) => DropdownMenu( + children: action.possibleValues!.map( + (ingame) { + return MenuButton( + child: Text(ingame.toString()), + onPressed: (_) { + _keyPair.touchPosition = Offset.zero; + _keyPair.physicalKey = null; + _keyPair.logicalKey = null; + _keyPair.inGameAction = action; + _keyPair.inGameActionValue = ingame; + widget.onUpdate(); + setState(() {}); + }, + ); + }, + ).toList(), + ), + ); + } else { + _keyPair.touchPosition = Offset.zero; + _keyPair.physicalKey = null; + _keyPair.logicalKey = null; + _keyPair.inGameAction = action; + _keyPair.inGameActionValue = null; + widget.onUpdate(); + setState(() {}); + } + }, + ); + }, + ); + }).toList(); + } } class SelectableCard extends StatelessWidget { diff --git a/lib/pages/customize.dart b/lib/pages/customize.dart index c81dc323..8c7e8cc6 100644 --- a/lib/pages/customize.dart +++ b/lib/pages/customize.dart @@ -97,10 +97,11 @@ class _CustomizeState extends State { final customApp = CustomApp(profileName: profileName); core.actionHandler.init(customApp); await core.settings.setKeyMap(customApp); + setState(() {}); } } else { - core.actionHandler.supportedApp = app; + core.actionHandler.init(app); await core.settings.setKeyMap(app); setState(() {}); } diff --git a/lib/utils/actions/base_actions.dart b/lib/utils/actions/base_actions.dart index 58fe74aa..20a346cd 100644 --- a/lib/utils/actions/base_actions.dart +++ b/lib/utils/actions/base_actions.dart @@ -53,23 +53,8 @@ abstract class BaseActions { debugPrint('Supported app: ${supportedApp?.name ?? "None"}'); if (supportedApp != null) { - final allButtons = core.connection.devices.map((e) => e.availableButtons).flatten().distinct(); - - final newButtons = allButtons.filter( - (button) => supportedApp.keymap.getKeyPair(button) == null, - ); - for (final button in newButtons) { - supportedApp.keymap.addKeyPair( - KeyPair( - touchPosition: Offset.zero, - buttons: [button], - inGameAction: button.action, - physicalKey: null, - logicalKey: null, - isLongPress: false, - ), - ); - } + final allButtons = core.connection.devices.map((e) => e.availableButtons).flatten().distinct().toList(); + supportedApp.keymap.addNewButtons(allButtons); } } diff --git a/lib/utils/keymap/buttons.dart b/lib/utils/keymap/buttons.dart index b10b8ee7..2ab0ddf9 100644 --- a/lib/utils/keymap/buttons.dart +++ b/lib/utils/keymap/buttons.dart @@ -20,8 +20,8 @@ enum InGameAction { toggleUi('Toggle UI', icon: RadixIcons.iconSwitch), navigateLeft('Navigate Left', icon: BootstrapIcons.signTurnLeft), navigateRight('Navigate Right', icon: BootstrapIcons.signTurnRight), - increaseResistance('Increase Resistance'), - decreaseResistance('Decrease Resistance'), + increaseResistance('Increase Resistance', icon: LucideIcons.chartNoAxesColumnIncreasing), + decreaseResistance('Decrease Resistance', icon: LucideIcons.chartNoAxesColumnDecreasing), // zwift openActionBar('Open Action Bar', alternativeTitle: 'Up', icon: BootstrapIcons.menuApp), diff --git a/lib/utils/keymap/keymap.dart b/lib/utils/keymap/keymap.dart index 129ebaca..93018d87 100644 --- a/lib/utils/keymap/keymap.dart +++ b/lib/utils/keymap/keymap.dart @@ -80,6 +80,21 @@ class Keymap { return allButtons.firstWhere((b) => b.name == name); } } + + void addNewButtons(List availableButtons) { + final newButtons = availableButtons.filter((button) => getKeyPair(button) == null); + for (final button in newButtons) { + addKeyPair( + KeyPair( + touchPosition: Offset.zero, + buttons: [button], + physicalKey: null, + logicalKey: null, + isLongPress: false, + ), + ); + } + } } class KeyPair { From c5e42bad4ac2bce285b5a8f44e673c970d42220e Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Thu, 18 Dec 2025 09:46:32 +0100 Subject: [PATCH 5/5] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60a95a02..4a7f7a98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ BikeControl now offers a free trial period of 5 days for all features, so you ca **Features**: - You will now be notified when a connection to your controller is lost +- improved UI of the Keymap customization screen ### 4.1.0 (16-12-2025)