fix: fix disconnect when selecting firmware for dfu
This commit is contained in:
@ -14,6 +14,13 @@ part 'bluetooth.g.dart';
|
|||||||
|
|
||||||
final log = Logger('BluetoothController');
|
final log = Logger('BluetoothController');
|
||||||
|
|
||||||
|
final backgroundBluetoothDisconnectSuppressionCountProvider =
|
||||||
|
StateProvider<int>((ref) => 0);
|
||||||
|
|
||||||
|
final backgroundBluetoothDisconnectSuppressedProvider = Provider<bool>((ref) {
|
||||||
|
return ref.watch(backgroundBluetoothDisconnectSuppressionCountProvider) > 0;
|
||||||
|
});
|
||||||
|
|
||||||
@Riverpod(keepAlive: true)
|
@Riverpod(keepAlive: true)
|
||||||
FlutterReactiveBle reactiveBle(Ref ref) {
|
FlutterReactiveBle reactiveBle(Ref ref) {
|
||||||
ref.keepAlive();
|
ref.keepAlive();
|
||||||
|
|||||||
@ -57,6 +57,9 @@ class _AbawoBtAppState extends ConsumerState<AbawoBtApp>
|
|||||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
if (state == AppLifecycleState.hidden ||
|
if (state == AppLifecycleState.hidden ||
|
||||||
state == AppLifecycleState.paused) {
|
state == AppLifecycleState.paused) {
|
||||||
|
if (ref.read(backgroundBluetoothDisconnectSuppressedProvider)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
unawaited(_disconnectBluetoothForBackground());
|
unawaited(_disconnectBluetoothForBackground());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -549,8 +549,19 @@ class _DeviceDetailsPageState extends ConsumerState<DeviceDetailsPage> {
|
|||||||
_firmwareUserMessage = null;
|
_firmwareUserMessage = null;
|
||||||
});
|
});
|
||||||
|
|
||||||
final result =
|
final suppressionCount = ref.read(
|
||||||
|
backgroundBluetoothDisconnectSuppressionCountProvider.notifier,
|
||||||
|
);
|
||||||
|
suppressionCount.state += 1;
|
||||||
|
|
||||||
|
final FirmwareFileSelectionResult result;
|
||||||
|
try {
|
||||||
|
result =
|
||||||
await _firmwareFileSelectionService.selectAndPrepareBootloaderDfu();
|
await _firmwareFileSelectionService.selectAndPrepareBootloaderDfu();
|
||||||
|
} finally {
|
||||||
|
suppressionCount.state =
|
||||||
|
suppressionCount.state <= 0 ? 0 : suppressionCount.state - 1;
|
||||||
|
}
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user