mirror of
https://github.com/jonasbark/swiftcontrol.git
synced 2026-11-29 09:11:17 +01:00
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:
@@ -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.
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user