feat: snackbar for flash err + disconnect on dfurecovery end
This commit is contained in:
@ -59,11 +59,43 @@ class _BootloaderRecoveryUpdatePageState
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
final service = _firmwareUpdateService;
|
||||
final bluetooth = ref.read(bluetoothProvider).valueOrNull;
|
||||
_firmwareUpdateService = null;
|
||||
unawaited(_firmwareProgressSubscription?.cancel());
|
||||
unawaited(_firmwareUpdateService?.dispose() ?? Future<void>.value());
|
||||
unawaited(() async {
|
||||
await service?.dispose();
|
||||
await _disconnectBootloaderIfStillConnected(bluetooth: bluetooth);
|
||||
}());
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _disconnectBootloaderIfStillConnected({
|
||||
BluetoothController? bluetooth,
|
||||
}) async {
|
||||
bluetooth ??= ref.read(bluetoothProvider).valueOrNull;
|
||||
if (bluetooth == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final currentState = bluetooth.currentConnectionState;
|
||||
if (currentState.$2 != widget.args.bootloaderDeviceId ||
|
||||
(currentState.$1 != ConnectionStatus.connected &&
|
||||
currentState.$1 != ConnectionStatus.connecting)) {
|
||||
return;
|
||||
}
|
||||
|
||||
await bluetooth.disconnect();
|
||||
}
|
||||
|
||||
Future<void> _dismissToDevices() async {
|
||||
await _disconnectBootloaderIfStillConnected();
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
context.go('/devices');
|
||||
}
|
||||
|
||||
Future<FirmwareUpdateService?> _ensureFirmwareUpdateService() async {
|
||||
if (_firmwareUpdateService != null) {
|
||||
return _firmwareUpdateService;
|
||||
@ -144,9 +176,24 @@ class _BootloaderRecoveryUpdatePageState
|
||||
if (!mounted || result.isOk()) {
|
||||
return;
|
||||
}
|
||||
await _disconnectBootloaderIfStillConnected();
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
final errorMessage = result.unwrapErr().toString();
|
||||
setState(() {
|
||||
_firmwareUserMessage = result.unwrapErr().toString();
|
||||
_firmwareUserMessage = errorMessage;
|
||||
});
|
||||
|
||||
if (errorMessage.startsWith(universalShifterBootMetadataWarningMessage)) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
'WARNING: The device failed writing to its internal storage. This might be a temporary problem. If it continues happening, the internal storage may be broken. If so, please contact abawo support',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _dfuPhaseText(DfuUpdateState state) {
|
||||
@ -190,7 +237,7 @@ class _BootloaderRecoveryUpdatePageState
|
||||
'0x${_dfuProgress.expectedOffset.toRadixString(16).padLeft(8, '0').toUpperCase()}',
|
||||
doneLabel: 'Back to devices',
|
||||
failedLabel: 'Back to devices',
|
||||
onDismiss: () => context.go('/devices'),
|
||||
onDismiss: () => unawaited(_dismissToDevices()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user