diff --git a/lib/connector/meshcore_connector.dart b/lib/connector/meshcore_connector.dart index 7672fff1..d3d16f4d 100644 --- a/lib/connector/meshcore_connector.dart +++ b/lib/connector/meshcore_connector.dart @@ -188,12 +188,14 @@ class MeshCoreConnector extends ChangeNotifier { String? _lastDeviceId; String? _lastDeviceDisplayName; bool _manualDisconnect = false; + /// Non-null while [disconnect] is tearing the transport down. Connect paths /// join it so a teardown cannot finish after a new connection and reset the /// state to `disconnected`. USB made this reachable: its native close now /// waits out the kernel's closing_wait off the UI isolate, so the teardown /// can outlive the tap that starts the next connection. Future? _activeDisconnect; + /// Set by [dispose]. A teardown started before disposal can still be running /// (the USB native close waits out the kernel's closing_wait off the UI /// isolate), so state publication is suppressed once the connector is gone. diff --git a/lib/services/usb_serial_service_native.dart b/lib/services/usb_serial_service_native.dart index f78210c7..cc76ddea 100644 --- a/lib/services/usb_serial_service_native.dart +++ b/lib/services/usb_serial_service_native.dart @@ -35,6 +35,7 @@ class UsbSerialService { String? _connectedPortKey; String? _connectedPortLabel; FlSerial? _serial; + /// Non-null while a disconnect teardown (native close in a helper isolate, /// then subscription cancel) is running. Future? _activeDisconnect; @@ -341,7 +342,6 @@ class UsbSerialService { } Future _disconnectInternal() async { - final portLabel = _connectedPortLabel ?? _connectedPortKey; _debugLogService?.info( 'USB disconnect starting port=${portLabel ?? 'unknown'}',