fix: fix disconnect when selecting firmware for dfu

This commit is contained in:
2026-05-03 19:24:57 +02:00
parent 3310387ec4
commit f5e5c3904f
3 changed files with 23 additions and 2 deletions

View File

@ -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();

View File

@ -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());
} }
} }

View File

@ -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;
} }