Skip to content

Commit 0468e50

Browse files
committed
Lots to do for con mode to idiot proof it
1 parent b565fa2 commit 0468e50

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

lib/Backend/Bluetooth/bluetooth_manager_plus.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,21 @@ Future<void> disconnect(String id) async {
382382
}
383383
}
384384

385+
Future<void> forgetBond(String id) async {
386+
if (!_didInitFlutterBluePlus) {
387+
return;
388+
}
389+
// removing bonds is supported on android
390+
if (Platform.isIOS) {
391+
return;
392+
}
393+
BluetoothDevice? device = flutterBluePlus.connectedDevices.firstWhereOrNull((element) => element.remoteId.str == id);
394+
if (device != null) {
395+
_bluetoothPlusLogger.info("forgetting ${device.advName}");
396+
await device.removeBond();
397+
}
398+
}
399+
385400
Future<void> connect(String id) async {
386401
if (!_didInitFlutterBluePlus) {
387402
return;

lib/Frontend/Widgets/manage_gear.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,25 +266,28 @@ class ManageGearConventionMode extends ConsumerWidget {
266266
),
267267
ListTile(
268268
title: Text(manageGearConModeToggleTitle()),
269-
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"),
269+
subtitle: Text(manageGearConModePincodeEnableDescription()),
270270
trailing: ValueListenableBuilder(
271271
valueListenable: device.deviceConnectionState,
272272
builder: (context, connectivityState, child) => Switch(
273273
value: device.baseStoredDevice.conModeEnabled,
274274
onChanged: connectivityState == ConnectivityState.connected
275275
? (value) async {
276-
//reject if gear disconnected
276+
//TODO: Validate the setting took correctly. Reboot check?
277277
if (value) {
278278
BluetoothMessage bluetoothMessage = BluetoothMessage(message: "SETPUSSKEY ${device.baseStoredDevice.conModePin}", device: device, timestamp: DateTime.timestamp());
279279
device.commandQueue.addCommand(bluetoothMessage);
280280
device.baseStoredDevice.conModeEnabled = true;
281281
ref.read(knownDevicesProvider.notifier).store();
282282
await Clipboard.setData(ClipboardData(text: device.baseStoredDevice.conModePin));
283283
} else {
284+
//TODO? if gear is disconnected and this is attempted, offer instructions to reset gear
284285
BluetoothMessage bluetoothMessage = BluetoothMessage(message: "STOPPUSSKEY", device: device, timestamp: DateTime.timestamp());
285286
device.commandQueue.addCommand(bluetoothMessage);
286287
device.baseStoredDevice.conModeEnabled = false;
287288
ref.read(knownDevicesProvider.notifier).store();
289+
forgetBond(device.baseStoredDevice.btMACAddress);
290+
//TODO: add IOS instructions for clearing bonds
288291
}
289292
}
290293
: null),

lib/Frontend/translation_string_definitions.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,9 @@ String manageGearConModeDescription() => Intl.message('Convention Mode is an add
397397

398398
String manageGearConModePincodeTitle() => Intl.message('View Pin Code', name: 'manageGearConModePincodeTitle', desc: 'The description for the pin mode button on the gear page');
399399

400+
String manageGearConModePincodeEnableDescription() =>
401+
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');
402+
400403
String manageGearConModePincodeCopy() => Intl.message('Copy to Clipboard', name: 'manageGearConModePincodeCopy', desc: 'The description for copy to clipboard button on the pin code dialog');
401404

402405
String manageGearConModeToggleTitle() => Intl.message('Enable Convention Mode', name: 'manageGearConModeToggleTitle', desc: 'The description for the convention mode enabled button on the gear page');

0 commit comments

Comments
 (0)