Skip to content

Fix priorities being lost when devices reconnect with new UIDs (Studio Display) - #31

Open
spamross wants to merge 1 commit into
tobi:mainfrom
spamross:fix/persist-priorities-across-uid-changes
Open

Fix priorities being lost when devices reconnect with new UIDs (Studio Display)#31
spamross wants to merge 1 commit into
tobi:mainfrom
spamross:fix/persist-priorities-across-uid-changes

Conversation

@spamross

@spamross spamross commented Aug 3, 2026

Copy link
Copy Markdown

Problem

Devices whose audio UID embeds the connection path — most notably the Apple Studio Display (AppleUSBAudioEngine:Apple Inc.:Studio Display:<serial>:8,9) — come back with a different UID after being unplugged, replugged, or moved to another port/hub.

Since every setting (priority order, speaker/headphone category, hidden and never-use flags) is keyed by UID, the device is treated as brand new on every reconnect: it drops to the bottom of the priority list and loses its category. Worse, savePriorities() overwrites the stored list with only the currently-visible devices, so the old entry is permanently erased the next time the user reorders anything.

Fix

  1. UID migration (PriorityManager.migrateDeviceUIDIfNeeded): when a device appears with an unknown UID whose name matches a known-but-disconnected device, all settings are transferred from the old UID to the new one. Hooked into refreshDevices() before rememberDevice.
  2. Name-based sort fallback in sortDevices(): a reconnected device lands in its saved slot by name even before migration runs.
  3. Merge-on-save in savePriorities(): disconnected devices keep their position in the stored list instead of being wiped when visible devices are reordered. The sort is also now explicitly stable (Swift sorted(by:) is not guaranteed stable), so unranked devices no longer shuffle.

No UI or behavior changes otherwise; settings storage format is unchanged (same UserDefaults keys).

Devices whose UID embeds the connection path (e.g. Apple Studio Display:
AppleUSBAudioEngine:Apple Inc.:Studio Display:<serial>:8,9) get a new UID
when replugged or moved to a different port. Since all settings are keyed
by UID, the device lost its priority slot, category, and hidden/never-use
flags on every reconnect. Worse, savePriorities() overwrote the stored
list with only currently-connected devices, permanently erasing the old
entry.

Three fixes:

1. UID migration: when an unknown UID appears whose name matches a known
   but disconnected device, transfer all settings to the new UID.
2. Name-based sort fallback: devices sort into their saved slot by name
   even before migration runs.
3. Merge-on-save: reordering visible devices no longer drops disconnected
   devices from the stored priority list. Sort is now also stable, so
   unranked devices don't shuffle.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant