From 0d612ce032bb090b59f656d12cabeccafc6adbb5 Mon Sep 17 00:00:00 2001 From: Jonas Bark Date: Wed, 10 Jun 2026 14:39:10 +0200 Subject: [PATCH] Re-attach connection listeners on in-place reconnect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- lib/bluetooth/connection.dart | 10 ++++++++++ lib/pages/proxy_device_details/connection_card.dart | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/bluetooth/connection.dart b/lib/bluetooth/connection.dart index 1a67c221..6814f334 100644 --- a/lib/bluetooth/connection.dart +++ b/lib/bluetooth/connection.dart @@ -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 connectDevice(BaseDevice device) => _connect(device); + Future _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. diff --git a/lib/pages/proxy_device_details/connection_card.dart b/lib/pages/proxy_device_details/connection_card.dart index d524aa8a..a1edf0af 100644 --- a/lib/pages/proxy_device_details/connection_card.dart +++ b/lib/pages/proxy_device_details/connection_card.dart @@ -166,7 +166,12 @@ class _ConnectionCardState extends State { 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); } }