From 9d0cfd25a429f7087e7dbb6e516b54f15ccf50c4 Mon Sep 17 00:00:00 2001 From: Nodeful Date: Fri, 19 Nov 2021 02:34:19 +0200 Subject: [PATCH] fix issue with volume being stuck on bluetooth & monterey --- native/app/Source/Application.swift | 15 +++++++++++++-- native/app/Source/Audio/Volume/Volume.swift | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/native/app/Source/Application.swift b/native/app/Source/Application.swift index ecddd921..1446df5e 100644 --- a/native/app/Source/Application.swift +++ b/native/app/Source/Application.swift @@ -43,6 +43,7 @@ class Application { static let audioPipelineIsRunning = EmitterKit.Event() static var audioPipelineIsRunningListener: EmitterKit.EventListener? private static var ignoreEvents = false + private static var ignoreVolumeEvents = false static var settings: Settings! @@ -223,7 +224,10 @@ class Application { static var ignoreNextDriverMuteEvent = false static func setupDriverDeviceEvents () { AudioDeviceEvents.on(.volumeChanged, onDevice: Driver.device!) { - if ignoreEvents { return } + if ignoreEvents || ignoreVolumeEvents { + return + } + if ignoreNextVolumeEvent { ignoreNextVolumeEvent = false return @@ -381,7 +385,9 @@ class Application { onDevice: selectedDevice!, retain: false ) { - if ignoreEvents { return } + if ignoreEvents || ignoreVolumeEvents { + return + } if ignoreNextVolumeEvent { ignoreNextVolumeEvent = false return @@ -389,7 +395,12 @@ class Application { let deviceVolume = selectedDevice!.virtualMasterVolume(direction: .playback)! let driverVolume = Driver.device!.virtualMasterVolume(direction: .playback)! if (deviceVolume != driverVolume) { + ignoreVolumeEvents = true Driver.device!.setVirtualMasterVolume(deviceVolume, direction: .playback) + Volume.gainChanged.emit(Double(deviceVolume)) + delay (50) { + ignoreVolumeEvents = false + } } } audioPipelineIsRunning.emit() diff --git a/native/app/Source/Audio/Volume/Volume.swift b/native/app/Source/Audio/Volume/Volume.swift index b95a7fc2..0c2a89d1 100644 --- a/native/app/Source/Audio/Volume/Volume.swift +++ b/native/app/Source/Audio/Volume/Volume.swift @@ -123,7 +123,7 @@ class Volume: StoreSubscriber { // MARK: - State typealias StoreSubscriberStateType = VolumeState - private let changeGainThread = DispatchQueue(label: "change-volume", qos: .background) + private let changeGainThread = DispatchQueue(label: "change-volume", qos: .userInteractive) private var latestChangeGainTask: DispatchWorkItem? private func performOnChangeGainThread (_ code: @escaping () -> Void) { latestChangeGainTask?.cancel()