Re-attach connection listeners on in-place reconnect

After an in-place "No connection" disconnect, selecting Virtual Shifting
again reconnected the BLE upstream but the connect never completed:
device.isConnected stayed false and the card hung on "connecting".

The listener that flips isConnected (and drives the handshake to
completion) is created only in _connect(), which runs once via the
auto-connect queue at app start. The first manual connect reuses that
listener; disconnect cancels it (so a BLE drop doesn't fire
auto-reconnect); the second manual connect via startProxy() had no
listener and never re-ran _connect.

Route the in-place reconnect through a new Connection.connectDevice()
wrapper over _connect, re-attaching the action / connection-state
listeners — the same path the working auto-connect uses — instead of
calling ProxyDevice.startProxy() directly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jonas Bark
2026-06-10 14:39:10 +02:00
parent 0db8cf0c31
commit 0d612ce032
2 changed files with 16 additions and 1 deletions

View File

@@ -501,6 +501,16 @@ class Connection {
}
}
/// Connect a device that is already in the list — used by the in-place
/// picker ("No connection" -> Virtual Shifting / Proxy on the same object).
///
/// Routes through the same [_connect] path the auto-connect queue uses so the
/// action / connection-state listeners are (re)attached. A bare
/// [ProxyDevice.startProxy] would reconnect the BLE upstream but leave
/// `isConnected` stuck — the listener that flips it is torn down on
/// disconnect and only [_connect] re-establishes it.
Future<void> connectDevice(BaseDevice device) => _connect(device);
Future<void> _connect(BaseDevice device) async {
// Cancel any stale subscriptions from a previous connect attempt so a retry
// doesn't stack listeners on the same device's streams.

View File

@@ -166,7 +166,12 @@ class _ConnectionCardState extends State<ConnectionCard> {
device.setRetrofitMode(next);
await core.settings.setRetrofitMode(device.trainerKey, next);
await core.settings.setAutoConnect(device.trainerKey, true);
await device.startProxy();
// Route through the connection manager (not device.startProxy directly) so
// the action / connection-state listeners are re-attached. After an
// in-place "No connection" disconnect those listeners are gone, and a bare
// startProxy reconnects BLE but never flips isConnected — the connect
// appears to hang.
await core.connection.connectDevice(device);
}
}