Refactor USB connection handling to use scheduled closure and improve error management in USB services

This commit is contained in:
just_stuff_tm
2026-03-02 04:11:52 -05:00
committed by just-stuff-tm
parent 4b24506310
commit dcad5c586d
4 changed files with 81 additions and 24 deletions
+10 -1
View File
@@ -1266,14 +1266,23 @@ class MeshCoreConnector extends ChangeNotifier {
_selfInfoRetryTimer?.cancel();
if (PlatformInfo.isWeb &&
_activeTransport == MeshCoreTransportType.bluetooth) {
_selfInfoRetryTimer = Timer(const Duration(seconds: 10), () {
var attempts = 0;
const maxAttempts = 3;
_selfInfoRetryTimer = Timer.periodic(const Duration(seconds: 10), (
timer,
) {
if (!isConnected || !_awaitingSelfInfo) {
timer.cancel();
return;
}
if (_isLoadingContacts || _isSyncingChannels || _channelSyncInFlight) {
return;
}
attempts += 1;
unawaited(sendFrame(buildAppStartFrame()));
if (attempts >= maxAttempts) {
timer.cancel();
}
});
return;
}