Fix priorities being lost when devices reconnect with new UIDs (Studio Display) - #31
Open
spamross wants to merge 1 commit into
Open
Fix priorities being lost when devices reconnect with new UIDs (Studio Display)#31spamross wants to merge 1 commit into
spamross wants to merge 1 commit into
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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 intorefreshDevices()beforerememberDevice.sortDevices(): a reconnected device lands in its saved slot by name even before migration runs.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 (Swiftsorted(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).