Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions AudioPriorityBar/AudioPriorityBarApp.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import SwiftUI
import CoreAudio
import AVFoundation

@main
struct AudioPriorityBarApp: App {
Expand Down Expand Up @@ -171,6 +172,30 @@ class AudioManager: ObservableObject {
applyHighestPriorityInput()
applyHighestPriorityOutput()
}
requestMicrophoneAccess()
}

/// macOS hides input device streams from apps without Microphone permission,
/// so input devices won't appear until access is granted. Request it on launch
/// and refresh the device list once the user responds.
private func requestMicrophoneAccess() {
switch AVCaptureDevice.authorizationStatus(for: .audio) {
case .authorized:
break
case .notDetermined:
AVCaptureDevice.requestAccess(for: .audio) { [weak self] _ in
Task { @MainActor in
guard let self else { return }
self.refreshDevices()
self.refreshMuteStatus()
if !self.isCustomMode {
self.applyHighestPriorityInput()
}
}
}
default:
break
}
}

private func setupMuteVolumeListener() {
Expand Down
2 changes: 2 additions & 0 deletions AudioPriorityBar/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@
<string>public.app-category.utilities</string>
<key>LSUIElement</key>
<true/>
<key>NSMicrophoneUsageDescription</key>
<string>Audio Priority Bar needs microphone access to list and manage your input (microphone) devices.</string>
</dict>
</plist>
16 changes: 15 additions & 1 deletion AudioPriorityBar/Views/MenuBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@ import SwiftUI
import CoreAudio
import AppKit

private struct ContentHeightKey: PreferenceKey {
static var defaultValue: CGFloat = 0
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = max(value, nextValue())
}
}

struct MenuBarView: View {
@EnvironmentObject var audioManager: AudioManager
@State private var contentHeight: CGFloat = 0

var body: some View {
VStack(spacing: 0) {
Expand Down Expand Up @@ -81,8 +89,14 @@ struct MenuBarView: View {
}
.padding(.horizontal, 16)
.padding(.vertical, 14)
.background(
GeometryReader { proxy in
Color.clear.preference(key: ContentHeightKey.self, value: proxy.size.height)
}
)
}
.frame(maxHeight: 420)
.frame(height: min(max(contentHeight, 1), 420))
.onPreferenceChange(ContentHeightKey.self) { contentHeight = $0 }

Divider()
.padding(.horizontal, 12)
Expand Down