-
-
Notifications
You must be signed in to change notification settings - Fork 8
feat(audio): add system default audio device selection to AudioDeviceSelector #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -50,6 +50,10 @@ struct AudioDeviceSelector: View { | |||||||||||||||||||||||||||||||||||||
| // Device list | ||||||||||||||||||||||||||||||||||||||
| ScrollView { | ||||||||||||||||||||||||||||||||||||||
| VStack(alignment: .leading, spacing: 0) { | ||||||||||||||||||||||||||||||||||||||
| systemDefaultRow | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Divider() | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if dacManager.availableDevices.isEmpty { | ||||||||||||||||||||||||||||||||||||||
| Text("No output devices found") | ||||||||||||||||||||||||||||||||||||||
| .font(.system(size: 12)) | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -90,7 +94,74 @@ struct AudioDeviceSelector: View { | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| // MARK: - Device Row | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private var systemDefaultRow: some View { | ||||||||||||||||||||||||||||||||||||||
| Button(action: { | ||||||||||||||||||||||||||||||||||||||
| selectSystemDefault() | ||||||||||||||||||||||||||||||||||||||
| }) { | ||||||||||||||||||||||||||||||||||||||
| HStack(spacing: 12) { | ||||||||||||||||||||||||||||||||||||||
| Image(systemName: isSystemDefaultSelected ? "checkmark.circle.fill" : "circle") | ||||||||||||||||||||||||||||||||||||||
| .font(AppFonts.labelLarge) | ||||||||||||||||||||||||||||||||||||||
| .foregroundColor( | ||||||||||||||||||||||||||||||||||||||
| isSystemDefaultSelected | ||||||||||||||||||||||||||||||||||||||
| ? theme.currentTheme.primaryColor : .secondary.opacity(0.3) | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
| .frame(width: 20) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| VStack(alignment: .leading, spacing: 2) { | ||||||||||||||||||||||||||||||||||||||
| Text("System Default") | ||||||||||||||||||||||||||||||||||||||
| .font(AppFonts.bodySmall) | ||||||||||||||||||||||||||||||||||||||
| .foregroundColor(.primary) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if let defaultDevice = dacManager.systemDefaultDevice { | ||||||||||||||||||||||||||||||||||||||
| HStack(spacing: 6) { | ||||||||||||||||||||||||||||||||||||||
| Text(defaultDevice.name) | ||||||||||||||||||||||||||||||||||||||
| .font(AppFonts.captionMedium) | ||||||||||||||||||||||||||||||||||||||
| .foregroundColor(.secondary) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||||||
| Text("•") | ||||||||||||||||||||||||||||||||||||||
| .font(AppFonts.captionMedium) | ||||||||||||||||||||||||||||||||||||||
| .foregroundColor(.secondary.opacity(0.5)) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Text("\(Int(defaultDevice.sampleRate)) Hz") | ||||||||||||||||||||||||||||||||||||||
| .font(AppFonts.captionMedium) | ||||||||||||||||||||||||||||||||||||||
| .foregroundColor(.secondary) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Text("•") | ||||||||||||||||||||||||||||||||||||||
| .font(AppFonts.captionMedium) | ||||||||||||||||||||||||||||||||||||||
| .foregroundColor(.secondary.opacity(0.5)) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Text(channelDescription(defaultDevice.channels)) | ||||||||||||||||||||||||||||||||||||||
| .font(AppFonts.captionMedium) | ||||||||||||||||||||||||||||||||||||||
| .foregroundColor(.secondary) | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+120
to
+137
|
||||||||||||||||||||||||||||||||||||||
| /* | |
| Text("•") | |
| .font(AppFonts.captionMedium) | |
| .foregroundColor(.secondary.opacity(0.5)) | |
| Text("\(Int(defaultDevice.sampleRate)) Hz") | |
| .font(AppFonts.captionMedium) | |
| .foregroundColor(.secondary) | |
| Text("•") | |
| .font(AppFonts.captionMedium) | |
| .foregroundColor(.secondary.opacity(0.5)) | |
| Text(channelDescription(defaultDevice.channels)) | |
| .font(AppFonts.captionMedium) | |
| .foregroundColor(.secondary) | |
| */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if the "System Default" row should display technical details (sample rate + channel configuration)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
nonisolated deinitschedules listener removal asynchronously and capturesselfweakly. By the time theTaskruns,selfwill often already be deallocated, so the listeners never get removed and CoreAudio callbacks can later dereference a freedclientDatapointer (use-after-free / crash). Also,nonisolatedis only valid for actor-isolated/global-actor-isolated types; ifDACManagerisn’t@MainActor, this likely won’t compile. Remove both listeners synchronously indeinit(noTask, noweak self), and if you truly need main-actor isolation, mark the type@MainActorand keep teardown synchronous withindeinit.