feat: snackbar for flash err + disconnect on dfurecovery end
This commit is contained in:
@ -57,6 +57,9 @@ const int universalShifterDfuFlagEncrypted = 0x01;
|
||||
const int universalShifterDfuFlagSigned = 0x02;
|
||||
const int universalShifterDfuFlagNone = 0x00;
|
||||
|
||||
const String universalShifterBootMetadataWarningMessage =
|
||||
'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';
|
||||
|
||||
const int errorSequence = 1;
|
||||
const int errorFtmsMissing = 2;
|
||||
const int errorPairingAuth = 3;
|
||||
|
||||
@ -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()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -651,6 +651,19 @@ class _DeviceDetailsPageState extends ConsumerState<DeviceDetailsPage> {
|
||||
}
|
||||
});
|
||||
|
||||
if (result.isErr() &&
|
||||
result.unwrapErr().toString().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',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (result.isOk()) {
|
||||
_hasLoadedDeviceTelemetry = false;
|
||||
unawaited(_loadDeviceTelemetry(force: true));
|
||||
|
||||
@ -353,6 +353,9 @@ class FirmwareUpdateService {
|
||||
);
|
||||
}
|
||||
_handleStatusPayload(statusResult.unwrap());
|
||||
if (_latestStatus?.code == DfuBootloaderStatusCode.bootMetadataError) {
|
||||
throw _DfuFailure(universalShifterBootMetadataWarningMessage);
|
||||
}
|
||||
_log.info('Initial bootloader DFU status read succeeded');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user