diff --git a/DynamicIsland/ContentView.swift b/DynamicIsland/ContentView.swift index 9ed11da..d0639dd 100644 --- a/DynamicIsland/ContentView.swift +++ b/DynamicIsland/ContentView.swift @@ -124,13 +124,13 @@ struct ContentView: View { } // Only close if mouse leaves and the notch is open and no popovers are active - if !hovering && vm.notchState == .open && !vm.isBatteryPopoverActive { + if !hovering && vm.notchState == .open && !vm.isBatteryPopoverActive && !vm.isClipboardPopoverActive && !vm.isColorPickerPopoverActive { // Add slight delay for stats tab to prevent accidental closure during layout changes let delay: Double = (coordinator.currentView == .stats) ? 0.2 : 0.0 DispatchQueue.main.asyncAfter(deadline: .now() + delay) { // Double-check conditions after delay - if !isHovering && vm.notchState == .open && !vm.isBatteryPopoverActive { + if !isHovering && vm.notchState == .open && !vm.isBatteryPopoverActive && !vm.isClipboardPopoverActive && !vm.isColorPickerPopoverActive { vm.close() } } @@ -185,6 +185,14 @@ struct ContentView: View { } } } + .onChange(of: vm.shouldRecheckHover) { _, _ in + // Recheck hover state when popovers are closed + DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { + if vm.notchState == .open && !vm.isBatteryPopoverActive && !vm.isClipboardPopoverActive && !vm.isColorPickerPopoverActive && !isHovering { + vm.close() + } + } + } .sensoryFeedback(.alignment, trigger: haptics) .contextMenu { SettingsLink(label: { @@ -527,7 +535,7 @@ struct ContentView: View { } // Close the notch if it's open and no popovers are active - if vm.notchState == .open && !vm.isBatteryPopoverActive { + if vm.notchState == .open && !vm.isBatteryPopoverActive && !vm.isClipboardPopoverActive && !vm.isColorPickerPopoverActive { vm.close() } } diff --git a/DynamicIsland/components/Notch/DynamicIslandHeader.swift b/DynamicIsland/components/Notch/DynamicIslandHeader.swift index 6f0a2ec..449d8b4 100644 --- a/DynamicIsland/components/Notch/DynamicIslandHeader.swift +++ b/DynamicIsland/components/Notch/DynamicIslandHeader.swift @@ -86,6 +86,16 @@ struct DynamicIslandHeader: View { .popover(isPresented: $showClipboardPopover, arrowEdge: .bottom) { ClipboardPopover() } + .onChange(of: showClipboardPopover) { isActive in + vm.isClipboardPopoverActive = isActive + + // If popover was closed, trigger a hover recheck + if !isActive { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { + vm.shouldRecheckHover.toggle() + } + } + } .onAppear { if Defaults[.enableClipboardManager] && !clipboardManager.isMonitoring { clipboardManager.startMonitoring() @@ -117,6 +127,16 @@ struct DynamicIslandHeader: View { .popover(isPresented: $showColorPickerPopover, arrowEdge: .bottom) { ColorPickerPopover() } + .onChange(of: showColorPickerPopover) { isActive in + vm.isColorPickerPopoverActive = isActive + + // If popover was closed, trigger a hover recheck + if !isActive { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { + vm.shouldRecheckHover.toggle() + } + } + } } if Defaults[.settingsIconInNotch] { diff --git a/DynamicIsland/models/DynamicIslandViewModel.swift b/DynamicIsland/models/DynamicIslandViewModel.swift index e29d114..85fe418 100644 --- a/DynamicIsland/models/DynamicIslandViewModel.swift +++ b/DynamicIsland/models/DynamicIslandViewModel.swift @@ -29,6 +29,9 @@ class DynamicIslandViewModel: NSObject, ObservableObject { @Published var hideOnClosed: Bool = true @Published var isHoveringCalendar: Bool = false @Published var isBatteryPopoverActive: Bool = false + @Published var isClipboardPopoverActive: Bool = false + @Published var isColorPickerPopoverActive: Bool = false + @Published var shouldRecheckHover: Bool = false let webcamManager = WebcamManager.shared @Published var isCameraExpanded: Bool = false