fix hid device functionality when accessibility service is active

This commit is contained in:
Jonas Bark
2025-12-05 20:07:48 +01:00
parent 1911ae08a7
commit 43be21f04b
4 changed files with 27 additions and 22 deletions

View File

@@ -1,11 +1,12 @@
### 4.0.0 (unreleased)
**Features:**
- a brand new design
- a brand-new design
- Accessibility Permission is now optional on Android
- Zwift is now fully supported on all operating systems
- you can choose between network based control or bluetooth based control
- BikeControl is now translated to German and French (contact me if you want to help with more translations)
- support for KICKR BIKE PRO
- BikeControl is now translated to German and French (contact me if you'd like to help with more translations)
- support for Wahoo KICKR BIKE PRO
- support for the OpenBikeControl protocol for supported Trainer apps
- this enables seamless and official integration, independent of the operating system
- learn more at https://openbikecontrol.org

View File

@@ -149,12 +149,16 @@ abstract class BaseDevice {
Widget showInformation(BuildContext context);
ControllerButton? getOrAddButton(String key, ControllerButton Function() creator) {
final button = core.actionHandler.supportedApp?.keymap.getOrAddButton(key, creator);
if (core.actionHandler.supportedApp is CustomApp) {
final button = core.actionHandler.supportedApp?.keymap.getOrAddButton(key, creator);
if (button != null && availableButtons.none((e) => e.name == button.name)) {
availableButtons.add(button);
core.settings.setKeyMap(core.actionHandler.supportedApp!);
if (button != null && availableButtons.none((e) => e.name == button.name)) {
availableButtons.add(button);
core.settings.setKeyMap(core.actionHandler.supportedApp!);
}
return button;
} else {
return null;
}
return button;
}
}

View File

@@ -5,7 +5,6 @@ import 'package:swift_control/bluetooth/devices/hid/hid_device.dart';
import 'package:swift_control/gen/l10n.dart';
import 'package:swift_control/utils/actions/base_actions.dart';
import 'package:swift_control/utils/core.dart';
import 'package:swift_control/utils/keymap/apps/custom_app.dart';
import 'package:swift_control/utils/keymap/buttons.dart';
import 'package:swift_control/widgets/keymap_explanation.dart';
@@ -29,20 +28,18 @@ class AndroidActions extends BaseActions {
});
hidKeyPressed().listen((keyPressed) {
if (supportedApp is CustomApp) {
final hidDevice = HidDevice(keyPressed.source);
final button = hidDevice.getOrAddButton(keyPressed.hidKey, () => ControllerButton(keyPressed.hidKey))!;
final hidDevice = HidDevice(keyPressed.source);
final button = hidDevice.getOrAddButton(keyPressed.hidKey, () => ControllerButton(keyPressed.hidKey))!;
var availableDevice = core.connection.controllerDevices.firstOrNullWhere((e) => e.name == hidDevice.name);
if (availableDevice == null) {
core.connection.addDevices([hidDevice]);
availableDevice = hidDevice;
}
if (keyPressed.keyDown) {
availableDevice.handleButtonsClicked([button]);
} else if (keyPressed.keyUp) {
availableDevice.handleButtonsClicked([]);
}
var availableDevice = core.connection.controllerDevices.firstOrNullWhere((e) => e.name == hidDevice.name);
if (availableDevice == null) {
core.connection.addDevices([hidDevice]);
availableDevice = hidDevice;
}
if (keyPressed.keyDown) {
availableDevice.handleButtonsClicked([button]);
} else if (keyPressed.keyUp) {
availableDevice.handleButtonsClicked([]);
}
});
}

View File

@@ -141,6 +141,9 @@ class _ScanWidgetState extends State<ScanWidget> {
setState(() {
_needsPermissions = permissions;
});
if (permissions.isEmpty) {
core.connection.performScanning();
}
});
}
}