Skip to content

fix: Make sure wired devices are listed before wireless ones#189

Merged
mykola-mokhnach merged 4 commits intomainfrom
list-order
Apr 13, 2026
Merged

fix: Make sure wired devices are listed before wireless ones#189
mykola-mokhnach merged 4 commits intomainfrom
list-order

Conversation

@mykola-mokhnach
Copy link
Copy Markdown
Collaborator

No description provided.

Copy link
Copy Markdown
Member

@KazuCocoa KazuCocoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lg entirely

Comment thread src/lib/usbmux/utils.ts
function wirelessRank<T extends { Properties: { ConnectionType: string } }>(
device: T,
): number {
return device.Properties.ConnectionType === 'Network' ? 1 : 0;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, could we add type for ConnectionType with Network or USB (instead of string)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be a breaking change. also, it might become confusing if Apple eventually decides to add some other value there.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Ensures Usbmux.listDevices() prioritizes wired (USB) devices over wireless (Network) entries when the same UDID appears multiple times, preventing Wi‑Fi rows from being returned first.

Changes:

  • Added prioritizeUsbOverNetworkForDuplicateUdids utility to reorder duplicate-UDID entries while preserving overall interleaving.
  • Applied the new ordering in Usbmux.listDevices().
  • Expanded unit tests to cover duplicate-UDID ordering scenarios and simplified Chai setup.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/lib/usbmux/utils.ts Introduces stable per-UDID reordering to prefer USB over Network for duplicate UDIDs.
src/lib/usbmux/index.ts Applies the new prioritization to the device list returned by listDevices().
test/unit/usbmux/usbmux-specs.ts Adds unit tests validating ordering behavior for duplicate UDIDs and interleaving cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/lib/usbmux/utils.ts Outdated
Comment on lines +3 to +4
* Reorders **in place across the original indices** for each UDID (no pulling one
* UDID into a contiguous block). Among equal rank, input order is kept (stable).
Copy link

Copilot AI Apr 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring says "Reorders in place" but the implementation clones the input array (const result = [...devices]) and returns a new array without mutating devices. Consider clarifying the wording (e.g., "reorders within the original indices" and explicitly stating it is non-mutating) to avoid misleading callers.

Suggested change
* Reorders **in place across the original indices** for each UDID (no pulling one
* UDID into a contiguous block). Among equal rank, input order is kept (stable).
* Returns a reordered copy across the original indices for each UDID (no pulling
* one UDID into a contiguous block). Among equal rank, input order is kept
* (stable). Does not mutate `devices`.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@mykola-mokhnach mykola-mokhnach merged commit 852655e into main Apr 13, 2026
11 checks passed
@mykola-mokhnach mykola-mokhnach deleted the list-order branch April 13, 2026 06:06
github-actions Bot pushed a commit that referenced this pull request Apr 13, 2026
## [0.44.2](v0.44.1...v0.44.2) (2026-04-13)

### Bug Fixes

* Make sure wired devices are listed before wireless ones ([#189](#189)) ([852655e](852655e))
@github-actions
Copy link
Copy Markdown

🎉 This PR is included in version 0.44.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants