Skip to content

Commit

Permalink
Lots to do for con mode to idiot proof it
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Dec 2, 2024
1 parent b565fa2 commit 0468e50
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
15 changes: 15 additions & 0 deletions lib/Backend/Bluetooth/bluetooth_manager_plus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,21 @@ Future<void> disconnect(String id) async {
}
}

Future<void> 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<void> connect(String id) async {
if (!_didInitFlutterBluePlus) {
return;
Expand Down
7 changes: 5 additions & 2 deletions lib/Frontend/Widgets/manage_gear.dart
Original file line number Diff line number Diff line change
Expand Up @@ -266,25 +266,28 @@ 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);
device.baseStoredDevice.conModeEnabled = true;
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),
Expand Down
3 changes: 3 additions & 0 deletions lib/Frontend/translation_string_definitions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit 0468e50

Please sign in to comment.