From 75c17246811f25bc3c7c7eaabbeb31b5d1fc64cb Mon Sep 17 00:00:00 2001 From: kylebonnici Date: Thu, 3 Oct 2024 14:13:37 +0200 Subject: [PATCH] Fix: auto connect to device with CLI when multiple devices are connected --- Changelog.md | 9 +++++++-- src/Device/deviceLister.ts | 25 +++++++++++-------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Changelog.md b/Changelog.md index 1ddff6515..ea1b65b12 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,11 +7,16 @@ This project does _not_ adhere to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) but contrary to it every new version is a new major version. -## 186.0.0 - Unreleased +## 186.0.0 - 2024-10-03 ### Changed -- DeviceSelector Abort controler is now aborted on the onDisconnected event +- DeviceSelector Abort controler now aborts on the onDisconnected event + +### Fixed + +- Auto connecting from CLI when multple devices are connected now works as + expected. ## 185.0.0 - 2024-09-20 diff --git a/src/Device/deviceLister.ts b/src/Device/deviceLister.ts index 143d37fe9..759869483 100644 --- a/src/Device/deviceLister.ts +++ b/src/Device/deviceLister.ts @@ -405,7 +405,7 @@ export const startWatchingDevices = deviceListing, d => { d.forEach(onDeviceArrived); - dispatch(autoSelectDeviceCLI(doSelectDevice)); + autoSelectDeviceCLI(d, doSelectDevice); }, error => { logger.error(error); @@ -459,21 +459,18 @@ const getAutoSelectDevice = (devices: Device[]) => { } }; -const autoSelectDeviceCLI = - ( - doSelectDevice: (device: Device, autoReselected: boolean) => void - ): AppThunk => - (_, getState) => { - if (!autoSelectDeviceCLISerialUsed) { - const autoSelectDevice = getAutoSelectDevice( - getState().device.devices - ); +const autoSelectDeviceCLI = ( + devices: Device[], + doSelectDevice: (device: Device, autoReselected: boolean) => void +) => { + if (!autoSelectDeviceCLISerialUsed) { + const autoSelectDevice = getAutoSelectDevice(devices); - if (autoSelectDevice) doSelectDevice(autoSelectDevice, true); + if (autoSelectDevice) doSelectDevice(autoSelectDevice, true); - autoSelectDeviceCLISerialUsed = true; - } - }; + autoSelectDeviceCLISerialUsed = true; + } +}; export const stopWatchingDevices = (callback?: () => void) => { if (stopNrfutilDevice) stopNrfutilDevice(callback);