mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
Fix: Brightness and Volume Control
This commit is contained in:
parent
f4bcb96906
commit
98c826aaae
11 changed files with 340 additions and 97 deletions
|
|
@ -87,8 +87,21 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
private var onboardingWindowController: NSWindowController?
|
||||
private var cancellables = Set<AnyCancellable>()
|
||||
|
||||
// Media key monitoring
|
||||
private var globalEventMonitor: Any?
|
||||
private var localEventMonitor: Any?
|
||||
|
||||
// Debouncing mechanism for window size updates
|
||||
private var windowSizeUpdateWorkItem: DispatchWorkItem?
|
||||
// let calendarManager = CalendarManager.shared
|
||||
// let webcamManager = WebcamManager.shared
|
||||
// var closeNotchWorkItem: DispatchWorkItem?
|
||||
// private var previousScreens: [NSScreen]?
|
||||
// private var onboardingWindowController: NSWindowController?
|
||||
// private var cancellables = Set<AnyCancellable>()
|
||||
//
|
||||
// // Debouncing mechanism for window size updates
|
||||
// private var windowSizeUpdateWorkItem: DispatchWorkItem?
|
||||
|
||||
private func debouncedUpdateWindowSize() {
|
||||
// Cancel any existing work item
|
||||
|
|
@ -108,10 +121,76 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
return false
|
||||
}
|
||||
|
||||
// MARK: - Media Key Monitoring
|
||||
|
||||
private func setupMediaKeyMonitoring() {
|
||||
// Monitor both global and local events to catch media keys
|
||||
globalEventMonitor = NSEvent.addGlobalMonitorForEvents(matching: .systemDefined) { [weak self] event in
|
||||
self?.handleSystemEvent(event)
|
||||
}
|
||||
|
||||
localEventMonitor = NSEvent.addLocalMonitorForEvents(matching: .systemDefined) { [weak self] event in
|
||||
self?.handleSystemEvent(event)
|
||||
return event
|
||||
}
|
||||
|
||||
print("🎹 Media key monitoring started using NSEvent")
|
||||
}
|
||||
|
||||
private func handleSystemEvent(_ event: NSEvent) {
|
||||
guard event.subtype.rawValue == 8 else { return }
|
||||
|
||||
let data1 = event.data1
|
||||
let keyCode = Int32((data1 & 0xFFFF0000) >> 16)
|
||||
let keyFlags = Int(data1 & 0x0000FFFF)
|
||||
let keyState = ((keyFlags & 0xFF00) >> 8) == 0xA // KeyDown
|
||||
let keyRepeat = (keyFlags & 0x1) != 0
|
||||
|
||||
guard keyState && !keyRepeat else { return } // Only handle key down, ignore repeats
|
||||
|
||||
switch keyCode {
|
||||
case NX_KEYTYPE_SOUND_UP, NX_KEYTYPE_SOUND_DOWN, NX_KEYTYPE_MUTE:
|
||||
print("🔊 Volume key detected: \(keyCode)")
|
||||
SystemHUDManager.shared.handleVolumeKeyEvent()
|
||||
case NX_KEYTYPE_BRIGHTNESS_UP, NX_KEYTYPE_BRIGHTNESS_DOWN:
|
||||
print("☀️ Brightness key detected: \(keyCode)")
|
||||
SystemHUDManager.shared.handleBrightnessKeyEvent()
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
private func stopMediaKeyMonitoring() {
|
||||
if let globalMonitor = globalEventMonitor {
|
||||
NSEvent.removeMonitor(globalMonitor)
|
||||
globalEventMonitor = nil
|
||||
}
|
||||
|
||||
if let localMonitor = localEventMonitor {
|
||||
NSEvent.removeMonitor(localMonitor)
|
||||
localEventMonitor = nil
|
||||
}
|
||||
|
||||
print("🎹 Media key monitoring stopped")
|
||||
}
|
||||
|
||||
// MARK: - MediaKeyApplicationDelegate (for future use)
|
||||
|
||||
func didDetectVolumeKey() {
|
||||
SystemHUDManager.shared.handleVolumeKeyEvent()
|
||||
}
|
||||
|
||||
func didDetectBrightnessKey() {
|
||||
SystemHUDManager.shared.handleBrightnessKeyEvent()
|
||||
}
|
||||
|
||||
func applicationWillTerminate(_ notification: Notification) {
|
||||
// Cancel any pending window size updates
|
||||
windowSizeUpdateWorkItem?.cancel()
|
||||
|
||||
// Stop media key monitoring
|
||||
stopMediaKeyMonitoring()
|
||||
|
||||
print("🚪 Application terminating - ensuring system HUD is restored...")
|
||||
|
||||
// Re-enable system HUD on app termination
|
||||
|
|
@ -302,6 +381,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|||
// Setup SystemHUD Manager
|
||||
SystemHUDManager.shared.setup(coordinator: coordinator)
|
||||
|
||||
// Setup media key monitoring
|
||||
setupMediaKeyMonitoring()
|
||||
|
||||
// Observe tab changes - use debounced updates
|
||||
coordinator.$currentView.sink { [weak self] newView in
|
||||
self?.debouncedUpdateWindowSize()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue