Skip to content

Commit

Permalink
fix issue with volume being stuck on bluetooth & monterey
Browse files Browse the repository at this point in the history
  • Loading branch information
nodeful committed Nov 19, 2021
1 parent 729a03d commit 9d0cfd2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions native/app/Source/Application.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Application {
static let audioPipelineIsRunning = EmitterKit.Event<Void>()
static var audioPipelineIsRunningListener: EmitterKit.EventListener<Void>?
private static var ignoreEvents = false
private static var ignoreVolumeEvents = false

static var settings: Settings!

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -381,15 +385,22 @@ class Application {
onDevice: selectedDevice!,
retain: false
) {
if ignoreEvents { return }
if ignoreEvents || ignoreVolumeEvents {
return
}
if ignoreNextVolumeEvent {
ignoreNextVolumeEvent = false
return
}
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()
Expand Down
2 changes: 1 addition & 1 deletion native/app/Source/Audio/Volume/Volume.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 9d0cfd2

Please sign in to comment.