feat: better pairing broken notification
This commit is contained in:
@ -732,6 +732,11 @@ class _DeviceDetailsPageState extends ConsumerState<DeviceDetailsPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (result.isErr()) {
|
if (result.isErr()) {
|
||||||
|
if (isBluetoothPairingRecoveryError(result.unwrapErr())) {
|
||||||
|
await showBluetoothPairingRecoveryDialog(context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
|
|||||||
@ -116,12 +116,11 @@ class _ConnectDevicePageState extends ConsumerState<ConnectDevicePage> {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Err(:final v):
|
case Err(:final v):
|
||||||
final error = v.toString();
|
if (isBluetoothPairingRecoveryError(v)) {
|
||||||
if (error.toLowerCase().contains('disconnected')) {
|
|
||||||
await showBluetoothPairingRecoveryDialog(context);
|
await showBluetoothPairingRecoveryDialog(context);
|
||||||
} else {
|
} else {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text('Connection unsuccessful:\n$error')),
|
SnackBar(content: Text('Connection unsuccessful:\n$v')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import 'package:abawo_bt_app/model/firmware_file_selection.dart';
|
|||||||
import 'package:abawo_bt_app/model/shifter_types.dart';
|
import 'package:abawo_bt_app/model/shifter_types.dart';
|
||||||
import 'package:abawo_bt_app/pages/bootloader_recovery_update_page.dart';
|
import 'package:abawo_bt_app/pages/bootloader_recovery_update_page.dart';
|
||||||
import 'package:abawo_bt_app/service/firmware_file_selection_service.dart';
|
import 'package:abawo_bt_app/service/firmware_file_selection_service.dart';
|
||||||
|
import 'package:abawo_bt_app/util/bluetooth_settings.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'
|
import 'package:flutter_reactive_ble/flutter_reactive_ble.dart'
|
||||||
show DiscoveredDevice, ScanMode, Uuid;
|
show DiscoveredDevice, ScanMode, Uuid;
|
||||||
@ -586,6 +587,8 @@ class _SavedDevicesListState extends ConsumerState<_SavedDevicesList> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
context.push('/device/${device.deviceAddress}');
|
context.push('/device/${device.deviceAddress}');
|
||||||
|
} else if (isBluetoothPairingRecoveryError(result.unwrapErr())) {
|
||||||
|
await showBluetoothPairingRecoveryDialog(context);
|
||||||
} else {
|
} else {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(
|
const SnackBar(
|
||||||
|
|||||||
@ -3,6 +3,10 @@ import 'dart:io';
|
|||||||
import 'package:app_settings/app_settings.dart';
|
import 'package:app_settings/app_settings.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
bool isBluetoothPairingRecoveryError(Object error) {
|
||||||
|
return error.toString().toLowerCase().contains('disconnected');
|
||||||
|
}
|
||||||
|
|
||||||
Future<bool> openBluetoothSettings() async {
|
Future<bool> openBluetoothSettings() async {
|
||||||
try {
|
try {
|
||||||
if (Platform.isAndroid) {
|
if (Platform.isAndroid) {
|
||||||
@ -23,7 +27,8 @@ Future<void> showBluetoothPairingRecoveryDialog(BuildContext context) {
|
|||||||
final content = isIOS
|
final content = isIOS
|
||||||
? 'The connection opened, then broke while reading the device. This is probably a pairing problem.\n\nGo to Settings, then Bluetooth, then forget this device. After that, come back and connect again.\n\nOr press Open Settings below. From the app settings page, press Back twice to reach Bluetooth settings, then forget this device.'
|
? 'The connection opened, then broke while reading the device. This is probably a pairing problem.\n\nGo to Settings, then Bluetooth, then forget this device. After that, come back and connect again.\n\nOr press Open Settings below. From the app settings page, press Back twice to reach Bluetooth settings, then forget this device.'
|
||||||
: 'The connection opened, then broke while reading the device. This is probably a pairing problem.\n\nOpen Bluetooth settings, remove/forget this device, then come back and connect again.';
|
: 'The connection opened, then broke while reading the device. This is probably a pairing problem.\n\nOpen Bluetooth settings, remove/forget this device, then come back and connect again.';
|
||||||
final settingsButtonLabel = isIOS ? 'Open Settings' : 'Open Bluetooth settings';
|
final settingsButtonLabel =
|
||||||
|
isIOS ? 'Open Settings' : 'Open Bluetooth settings';
|
||||||
|
|
||||||
return showDialog<void>(
|
return showDialog<void>(
|
||||||
context: context,
|
context: context,
|
||||||
|
|||||||
23
test/util/bluetooth_settings_test.dart
Normal file
23
test/util/bluetooth_settings_test.dart
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import 'package:abawo_bt_app/util/bluetooth_settings.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('isBluetoothPairingRecoveryError', () {
|
||||||
|
test('detects immediate disconnect connection failures', () {
|
||||||
|
expect(
|
||||||
|
isBluetoothPairingRecoveryError(
|
||||||
|
'Failed to connect to device-id: disconnected',
|
||||||
|
),
|
||||||
|
isTrue,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('does not classify generic connection failures as pairing recovery',
|
||||||
|
() {
|
||||||
|
expect(
|
||||||
|
isBluetoothPairingRecoveryError('Timed out connecting to device-id'),
|
||||||
|
isFalse,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user