mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-29 08:04:32 +00:00
Update settings and headphone mute condition
This commit is contained in:
parent
120cd50e0e
commit
a29f73a99b
2 changed files with 29 additions and 7 deletions
|
|
@ -2294,6 +2294,7 @@ struct About: View {
|
||||||
.padding(.horizontal, 10)
|
.padding(.horizontal, 10)
|
||||||
}
|
}
|
||||||
.frame(maxWidth: .infinity, alignment: .center)
|
.frame(maxWidth: .infinity, alignment: .center)
|
||||||
|
.background(Color(nsColor: .controlBackgroundColor))
|
||||||
}
|
}
|
||||||
.toolbar {
|
.toolbar {
|
||||||
// Button("Welcome window") {
|
// Button("Welcome window") {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,14 @@ final class SystemChangesObserver: MediaKeyInterceptorDelegate {
|
||||||
private let keyboardBacklightController = SystemKeyboardBacklightController.shared
|
private let keyboardBacklightController = SystemKeyboardBacklightController.shared
|
||||||
private let mediaKeyInterceptor = MediaKeyInterceptor.shared
|
private let mediaKeyInterceptor = MediaKeyInterceptor.shared
|
||||||
|
|
||||||
|
private static let headsetIconSymbols: Set<String> = [
|
||||||
|
"airpods",
|
||||||
|
"airpodspro",
|
||||||
|
"airpodsmax",
|
||||||
|
"beats.headphones",
|
||||||
|
"headphones"
|
||||||
|
]
|
||||||
|
|
||||||
private let standardVolumeStep: Float = 1.0 / 16.0
|
private let standardVolumeStep: Float = 1.0 / 16.0
|
||||||
private let standardBrightnessStep: Float = 1.0 / 16.0
|
private let standardBrightnessStep: Float = 1.0 / 16.0
|
||||||
private let fineStepDivisor: Float = 4.0
|
private let fineStepDivisor: Float = 4.0
|
||||||
|
|
@ -30,11 +38,16 @@ final class SystemChangesObserver: MediaKeyInterceptorDelegate {
|
||||||
volumeController.onVolumeChange = { [weak self] volume, muted in
|
volumeController.onVolumeChange = { [weak self] volume, muted in
|
||||||
guard let self, self.volumeEnabled else { return }
|
guard let self, self.volumeEnabled else { return }
|
||||||
let value = muted ? 0 : volume
|
let value = muted ? 0 : volume
|
||||||
self.sendVolumeNotification(value: value)
|
Task { @MainActor in
|
||||||
|
self.sendVolumeNotification(value: value, isMuted: muted)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
volumeController.onRouteChange = { [weak self] in
|
volumeController.onRouteChange = { [weak self] in
|
||||||
guard let self, self.volumeEnabled else { return }
|
guard let self, self.volumeEnabled else { return }
|
||||||
self.sendVolumeNotification(value: self.volumeController.isMuted ? 0 : self.volumeController.currentVolume)
|
let muted = self.volumeController.isMuted
|
||||||
|
Task { @MainActor in
|
||||||
|
self.sendVolumeNotification(value: muted ? 0 : self.volumeController.currentVolume, isMuted: muted)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
volumeController.start()
|
volumeController.start()
|
||||||
|
|
||||||
|
|
@ -162,7 +175,8 @@ final class SystemChangesObserver: MediaKeyInterceptorDelegate {
|
||||||
|
|
||||||
// MARK: - HUD Dispatch
|
// MARK: - HUD Dispatch
|
||||||
|
|
||||||
private func sendVolumeNotification(value: Float) {
|
@MainActor
|
||||||
|
private func sendVolumeNotification(value: Float, isMuted: Bool) {
|
||||||
if HUDSuppressionCoordinator.shared.shouldSuppressVolumeHUD {
|
if HUDSuppressionCoordinator.shared.shouldSuppressVolumeHUD {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -177,10 +191,8 @@ final class SystemChangesObserver: MediaKeyInterceptorDelegate {
|
||||||
|
|
||||||
// Send to Vertical HUD if enabled
|
// Send to Vertical HUD if enabled
|
||||||
if Defaults[.enableVerticalHUD] {
|
if Defaults[.enableVerticalHUD] {
|
||||||
Task { @MainActor in
|
let icon = resolvedVolumeIcon(isMuted: isMuted)
|
||||||
let icon = BluetoothAudioManager.shared.activeDeviceIconSymbol() ?? ""
|
VerticalHUDWindowManager.shared.show(type: .volume, value: CGFloat(value), icon: icon)
|
||||||
VerticalHUDWindowManager.shared.show(type: .volume, value: CGFloat(value), icon: icon)
|
|
||||||
}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -205,6 +217,15 @@ final class SystemChangesObserver: MediaKeyInterceptorDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MainActor
|
||||||
|
private func resolvedVolumeIcon(isMuted: Bool) -> String {
|
||||||
|
guard let icon = BluetoothAudioManager.shared.activeDeviceIconSymbol() else { return "" }
|
||||||
|
if isMuted && Self.headsetIconSymbols.contains(icon) {
|
||||||
|
return "headphones.slash"
|
||||||
|
}
|
||||||
|
return icon
|
||||||
|
}
|
||||||
|
|
||||||
private func sendBrightnessNotification(value: Float) {
|
private func sendBrightnessNotification(value: Float) {
|
||||||
// Send to Circular HUD if enabled
|
// Send to Circular HUD if enabled
|
||||||
if Defaults[.enableCircularHUD] {
|
if Defaults[.enableCircularHUD] {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue