From 990f2bd33d1efdf3510846c82addffeca647dc6b Mon Sep 17 00:00:00 2001 From: just-stuff-tm Date: Sun, 15 Mar 2026 21:06:18 -0400 Subject: [PATCH] addressed copilot issues still need pr #301 for smoke tests to pass --- lib/connector/meshcore_connector.dart | 11 ++++++++++- lib/services/linux_ble_pairing_service.dart | 12 ++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index f176cf6..24d434e 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -1701,7 +1701,9 @@ class MeshCoreConnector extends ChangeNotifier { remoteId, ); final needsBondRecovery = - pluginBondState != BmBondStateEnum.bonded || !trustedByBluez; + (pluginBondState != null && + pluginBondState != BmBondStateEnum.bonded) || + !trustedByBluez; if (!needsBondRecovery) { return false; } @@ -1770,6 +1772,11 @@ class MeshCoreConnector extends ChangeNotifier { 'bluetoothctl unavailable; continuing with plugin bonded state', tag: 'BLE Connect', ); + } else if (beforeBondState == null) { + _appDebugLogService?.warn( + 'bluetoothctl unavailable and plugin bond state is unknown; skipping Linux pairing fallback', + tag: 'BLE Connect', + ); } else { _appDebugLogService?.warn( 'bluetoothctl unavailable and device is not bonded; skipping Linux pairing fallback', @@ -1817,6 +1824,8 @@ class MeshCoreConnector extends ChangeNotifier { _appDebugLogService?.info( beforeBondState == BmBondStateEnum.bonded ? 'Linux BLE device still untrusted after repair; requesting pair' + : beforeBondState == null + ? 'Linux BLE device bond state unknown; requesting pair' : 'Linux BLE device not bonded, requesting pair', tag: 'BLE Connect', ); diff --git a/lib/services/linux_ble_pairing_service.dart b/lib/services/linux_ble_pairing_service.dart index b3d4fc4..8ed52f6 100644 --- a/lib/services/linux_ble_pairing_service.dart +++ b/lib/services/linux_ble_pairing_service.dart @@ -12,9 +12,9 @@ typedef ProcessRunFn = /// This is used only as a fallback when BlueZ pairing via flutter_blue_plus /// fails to surface agent prompts in-app. class LinuxBlePairingService { - /// Maximum number of retry attempts for the pairing flow. + /// Maximum number of pairing attempts (initial + retries). /// Covers one remove-and-retry plus one proactive-PIN retry. - static const int _maxRetries = 2; + static const int _maxAttempts = 3; static const Duration _processExitTimeout = Duration(seconds: 6); static const Duration _pairingCleanupTimeout = Duration(seconds: 5); @@ -110,7 +110,7 @@ class LinuxBlePairingService { var proactivePinRetryUsed = false; Future Function()? currentPinProvider = onRequestPin; - for (var attempt = 0; attempt <= _maxRetries; attempt++) { + for (var attempt = 0; attempt < _maxAttempts; attempt++) { final result = await _runPairingAttempt( remoteId: remoteId, timeout: timeout, @@ -129,7 +129,7 @@ class LinuxBlePairingService { removeRetryUsed = true; onLog?.call( 'Pairing failed; removing cached bond and retrying ' - '(attempt ${attempt + 1}/$_maxRetries)', + '(attempt ${attempt + 1}/$_maxAttempts)', ); await _removeDevice(remoteId, onLog: onLog); continue; @@ -140,7 +140,7 @@ class LinuxBlePairingService { proactivePinRetryUsed = true; onLog?.call( 'Pairing failed before PIN challenge; requesting PIN for ' - 'proactive retry (attempt ${attempt + 1}/$_maxRetries)', + 'proactive retry (attempt ${attempt + 1}/$_maxAttempts)', ); final pin = await currentPinProvider(); if (pin == null) { @@ -162,7 +162,7 @@ class LinuxBlePairingService { proactivePinRetryUsed = true; onLog?.call( 'No PIN challenge observed before timeout; requesting PIN for ' - 'proactive retry (attempt ${attempt + 1}/$_maxRetries)', + 'proactive retry (attempt ${attempt + 1}/$_maxAttempts)', ); final pin = await currentPinProvider(); if (pin == null) {