Skip to content

Commit

Permalink
Merge pull request #945 from NordicSemiconductor/fix/auto-connect-cli
Browse files Browse the repository at this point in the history
Fix: auto connect to device with CLI when multiple devices are connected
  • Loading branch information
kylebonnici authored Oct 3, 2024
2 parents 253b334 + 75c1724 commit bce2590
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
9 changes: 7 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 11 additions & 14 deletions src/Device/deviceLister.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export const startWatchingDevices =
deviceListing,
d => {
d.forEach(onDeviceArrived);
dispatch(autoSelectDeviceCLI(doSelectDevice));
autoSelectDeviceCLI(d, doSelectDevice);
},
error => {
logger.error(error);
Expand Down Expand Up @@ -459,21 +459,18 @@ const getAutoSelectDevice = (devices: Device[]) => {
}
};

const autoSelectDeviceCLI =
(
doSelectDevice: (device: Device, autoReselected: boolean) => void
): AppThunk<RootState> =>
(_, 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);
Expand Down

0 comments on commit bce2590

Please sign in to comment.