From 0468e50f33e47b1cdb20185164b5d43380896bc8 Mon Sep 17 00:00:00 2001 From: Codel1417 Date: Sun, 1 Dec 2024 19:02:02 -0500 Subject: [PATCH] Lots to do for con mode to idiot proof it --- lib/Backend/Bluetooth/bluetooth_manager_plus.dart | 15 +++++++++++++++ lib/Frontend/Widgets/manage_gear.dart | 7 +++++-- lib/Frontend/translation_string_definitions.dart | 3 +++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/Backend/Bluetooth/bluetooth_manager_plus.dart b/lib/Backend/Bluetooth/bluetooth_manager_plus.dart index c5b81ce1..05d6a7c8 100644 --- a/lib/Backend/Bluetooth/bluetooth_manager_plus.dart +++ b/lib/Backend/Bluetooth/bluetooth_manager_plus.dart @@ -382,6 +382,21 @@ Future disconnect(String id) async { } } +Future forgetBond(String id) async { + if (!_didInitFlutterBluePlus) { + return; + } + // removing bonds is supported on android + if (Platform.isIOS) { + return; + } + BluetoothDevice? device = flutterBluePlus.connectedDevices.firstWhereOrNull((element) => element.remoteId.str == id); + if (device != null) { + _bluetoothPlusLogger.info("forgetting ${device.advName}"); + await device.removeBond(); + } +} + Future connect(String id) async { if (!_didInitFlutterBluePlus) { return; diff --git a/lib/Frontend/Widgets/manage_gear.dart b/lib/Frontend/Widgets/manage_gear.dart index 1b0c4db1..ef500db4 100644 --- a/lib/Frontend/Widgets/manage_gear.dart +++ b/lib/Frontend/Widgets/manage_gear.dart @@ -266,14 +266,14 @@ class ManageGearConventionMode extends ConsumerWidget { ), ListTile( title: Text(manageGearConModeToggleTitle()), - subtitle: Text("Upon enabling 'Convention Mode' your gear will be rebooted and you will be prompted to enter the pincode. Please view and memorize the pincode before enabling"), + subtitle: Text(manageGearConModePincodeEnableDescription()), trailing: ValueListenableBuilder( valueListenable: device.deviceConnectionState, builder: (context, connectivityState, child) => Switch( value: device.baseStoredDevice.conModeEnabled, onChanged: connectivityState == ConnectivityState.connected ? (value) async { - //reject if gear disconnected + //TODO: Validate the setting took correctly. Reboot check? if (value) { BluetoothMessage bluetoothMessage = BluetoothMessage(message: "SETPUSSKEY ${device.baseStoredDevice.conModePin}", device: device, timestamp: DateTime.timestamp()); device.commandQueue.addCommand(bluetoothMessage); @@ -281,10 +281,13 @@ class ManageGearConventionMode extends ConsumerWidget { ref.read(knownDevicesProvider.notifier).store(); await Clipboard.setData(ClipboardData(text: device.baseStoredDevice.conModePin)); } else { + //TODO? if gear is disconnected and this is attempted, offer instructions to reset gear BluetoothMessage bluetoothMessage = BluetoothMessage(message: "STOPPUSSKEY", device: device, timestamp: DateTime.timestamp()); device.commandQueue.addCommand(bluetoothMessage); device.baseStoredDevice.conModeEnabled = false; ref.read(knownDevicesProvider.notifier).store(); + forgetBond(device.baseStoredDevice.btMACAddress); + //TODO: add IOS instructions for clearing bonds } } : null), diff --git a/lib/Frontend/translation_string_definitions.dart b/lib/Frontend/translation_string_definitions.dart index 9412b35f..5c578866 100644 --- a/lib/Frontend/translation_string_definitions.dart +++ b/lib/Frontend/translation_string_definitions.dart @@ -397,6 +397,9 @@ String manageGearConModeDescription() => Intl.message('Convention Mode is an add String manageGearConModePincodeTitle() => Intl.message('View Pin Code', name: 'manageGearConModePincodeTitle', desc: 'The description for the pin mode button on the gear page'); +String manageGearConModePincodeEnableDescription() => + Intl.message("Upon enabling 'Convention Mode' your gear will be rebooted and you will be prompted to enter the pincode. The pincode will be copied to the clipboard", name: 'manageGearConModePincodeEnableDescription', desc: 'The description for the pin mode button on the gear page'); + String manageGearConModePincodeCopy() => Intl.message('Copy to Clipboard', name: 'manageGearConModePincodeCopy', desc: 'The description for copy to clipboard button on the pin code dialog'); String manageGearConModeToggleTitle() => Intl.message('Enable Convention Mode', name: 'manageGearConModeToggleTitle', desc: 'The description for the convention mode enabled button on the gear page');