mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-12-03 02:24:28 +01:00
Merge branch 'copilot/implement-in-app-purchase' into copilot/add-steering-detection-algorithm
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -12,13 +12,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';
|
||||
@@ -327,20 +325,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) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
|
||||
@@ -18,13 +18,15 @@ class OpenBikeControlMdnsEmulator extends TrainerConnection {
|
||||
ServerSocket? _server;
|
||||
Registration? _mdnsRegistration;
|
||||
|
||||
static const String connectionTitle = 'OpenBikeControl mDNS Emulator';
|
||||
|
||||
final ValueNotifier<AppInfo?> connectedApp = ValueNotifier(null);
|
||||
|
||||
Socket? _socket;
|
||||
|
||||
OpenBikeControlMdnsEmulator()
|
||||
: super(
|
||||
title: 'OpenBikeControl mDNS Emulator',
|
||||
title: connectionTitle,
|
||||
supportedActions: InGameAction.values,
|
||||
);
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
);
|
||||
|
||||
|
||||
@@ -404,5 +404,9 @@
|
||||
"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, reliable connection methods - stay tuned for updates!",
|
||||
"accessories": "Accessories",
|
||||
"manualyControllingButton": "Control {trainerApp} manually!"
|
||||
}
|
||||
|
||||
@@ -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,69 @@ 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<ButtonEditPage> createState() => _ButtonEditPageState();
|
||||
}
|
||||
|
||||
class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
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<BaseNotification> _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;
|
||||
});
|
||||
_triggerBump();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@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
|
||||
@@ -54,7 +100,7 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
padding: const EdgeInsets.only(right: 26.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
spacing: 16,
|
||||
spacing: 8,
|
||||
children: [
|
||||
SizedBox(height: 16),
|
||||
Row(
|
||||
@@ -64,7 +110,14 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
spacing: 8,
|
||||
children: [
|
||||
Text('Editing').h3,
|
||||
ButtonWidget(button: widget.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),
|
||||
@@ -86,140 +139,29 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
),
|
||||
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) ...[
|
||||
@@ -243,22 +185,22 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
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 +216,15 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
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<void>(
|
||||
context: context,
|
||||
barrierDismissible: false, // enable Escape key
|
||||
builder: (c) => HotKeyListenerDialog(
|
||||
customApp: core.actionHandler.supportedApp! as CustomApp,
|
||||
keyPair: keyPair,
|
||||
keyPair: _keyPair,
|
||||
),
|
||||
);
|
||||
setState(() {});
|
||||
@@ -293,18 +235,18 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
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<bool?>(
|
||||
MaterialPageRoute(
|
||||
builder: (c) => TouchAreaSetupPage(
|
||||
keyPair: keyPair,
|
||||
keyPair: _keyPair,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -317,9 +259,9 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
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 +270,8 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
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 +280,8 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
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 +291,8 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
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 +301,8 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
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 +310,8 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
),
|
||||
MenuButton(
|
||||
onPressed: (c) {
|
||||
keyPair.physicalKey = PhysicalKeyboardKey.audioVolumeUp;
|
||||
keyPair.logicalKey = null;
|
||||
_keyPair.physicalKey = PhysicalKeyboardKey.audioVolumeUp;
|
||||
_keyPair.logicalKey = null;
|
||||
|
||||
setState(() {});
|
||||
widget.onUpdate();
|
||||
@@ -379,8 +321,8 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
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 +344,11 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
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 +361,8 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
(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 +374,8 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
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 +391,11 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
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 +403,13 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
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(() {});
|
||||
},
|
||||
@@ -481,6 +423,56 @@ class _ButtonEditPageState extends State<ButtonEditPage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildTrainerConnectionActions(List<InGameAction> 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 {
|
||||
|
||||
@@ -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<ButtonSimulator> {
|
||||
|
||||
@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<ButtonSimulator> {
|
||||
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<ButtonSimulator> {
|
||||
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);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import 'dart:async';
|
||||
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 +129,23 @@ class _ConfigurationPageState extends State<ConfigurationPage> {
|
||||
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(
|
||||
|
||||
@@ -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<CustomizePage> {
|
||||
@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<CustomizePage> {
|
||||
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<CustomizePage> {
|
||||
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 {
|
||||
@@ -105,10 +97,11 @@ class _CustomizeState extends State<CustomizePage> {
|
||||
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(() {});
|
||||
}
|
||||
|
||||
@@ -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<DevicePage> 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<DevicePage> 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<DevicePage> 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<DevicePage> 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(),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -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<TrainerPage> 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: () {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -235,6 +235,15 @@ class CoreLogic {
|
||||
if (isRemoteControlEnabled) core.remotePairing,
|
||||
].filter((e) => e.isConnected.value).toList();
|
||||
|
||||
List<TrainerConnection> 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<TrainerConnection> get trainerConnections => [
|
||||
if (showMyWhooshLink) core.whooshLink,
|
||||
if (showObpMdnsEmulator) core.obpMdnsEmulator,
|
||||
|
||||
@@ -15,6 +15,7 @@ class MyWhoosh extends SupportedApp {
|
||||
compatibleTargets: Target.values,
|
||||
supportsZwiftEmulation: false,
|
||||
supportsOpenBikeProtocol: screenshotMode,
|
||||
star: true,
|
||||
keymap: Keymap(
|
||||
keyPairs: [
|
||||
...ControllerButton.values
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<SupportedApp> supportedApps = [
|
||||
|
||||
@@ -21,8 +21,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),
|
||||
|
||||
@@ -80,6 +80,21 @@ class Keymap {
|
||||
return allButtons.firstWhere((b) => b.name == name);
|
||||
}
|
||||
}
|
||||
|
||||
void addNewButtons(List<ControllerButton> 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 {
|
||||
|
||||
@@ -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<KeymapExplanation> {
|
||||
late StreamSubscription<void> _updateStreamListener;
|
||||
|
||||
late StreamSubscription<BaseNotification> _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<KeymapExplanation> {
|
||||
}
|
||||
}
|
||||
|
||||
@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<KeymapExplanation> {
|
||||
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<KeymapExplanation> {
|
||||
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<KeymapExplanation> {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _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 {
|
||||
|
||||
Reference in New Issue
Block a user