Skip to content

Commit c5ad342

Browse files
committed
refactor: reuse VolumeMonitor's AudioDeviceManager for device switching
1 parent 73157e3 commit c5ad342

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

VolumeGrid/Audio/VolumeMonitor.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,10 @@ class VolumeMonitor: ObservableObject {
747747
hudEventSubject.send(event)
748748
}
749749

750+
nonisolated func setDefaultOutputDevice(_ deviceID: AudioDeviceID) -> Bool {
751+
deviceManager.setDefaultOutputDevice(deviceID)
752+
}
753+
750754
private func updateVolumeSupportState(_ isSupported: Bool) {
751755
isCurrentDeviceVolumeSupported = isSupported
752756
if !isSupported {

VolumeGrid/StatusBar/StatusBarController.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,7 @@ final class StatusBarController {
324324
guard let deviceIDNumber = sender.representedObject as? NSNumber else { return }
325325
let deviceID = AudioDeviceID(deviceIDNumber.uint32Value)
326326

327-
let deviceManager = AudioDeviceManager()
328-
let success = deviceManager.setDefaultOutputDevice(deviceID)
327+
let success = volumeMonitor.setDefaultOutputDevice(deviceID)
329328

330329
if !success {
331330
showError("Failed to switch audio device")

0 commit comments

Comments
 (0)