mirror of
https://github.com/FBukovina/Atoll.git
synced 2026-10-27 15:14:33 +00:00
ContentView updated but still NowPlaying progress fucked
This commit is contained in:
parent
80de66b3ad
commit
4136f6d9b9
1 changed files with 29 additions and 51 deletions
|
|
@ -13,6 +13,7 @@ import KeyboardShortcuts
|
||||||
import SwiftUI
|
import SwiftUI
|
||||||
import SwiftUIIntrospect
|
import SwiftUIIntrospect
|
||||||
|
|
||||||
|
@MainActor
|
||||||
struct ContentView: View {
|
struct ContentView: View {
|
||||||
@EnvironmentObject var vm: DynamicIslandViewModel
|
@EnvironmentObject var vm: DynamicIslandViewModel
|
||||||
@EnvironmentObject var webcamManager: WebcamManager
|
@EnvironmentObject var webcamManager: WebcamManager
|
||||||
|
|
@ -65,9 +66,10 @@ struct ContentView: View {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@State private var hoverTask: Task<Void, Never>?
|
||||||
@State private var isHovering: Bool = false
|
@State private var isHovering: Bool = false
|
||||||
@State private var hoverWorkItem: DispatchWorkItem?
|
@State private var hoverWorkItem: DispatchWorkItem? // Used by handleSimpleHover for stats closing logic
|
||||||
@State private var debounceWorkItem: DispatchWorkItem?
|
@State private var debounceWorkItem: DispatchWorkItem? // Used by handleSimpleHover
|
||||||
|
|
||||||
@State private var isHoverStateChanging: Bool = false
|
@State private var isHoverStateChanging: Bool = false
|
||||||
@State private var isStatsTransitioning: Bool = false
|
@State private var isStatsTransitioning: Bool = false
|
||||||
|
|
@ -643,72 +645,48 @@ struct ContentView: View {
|
||||||
|
|
||||||
/// Handle hover state changes with debouncing
|
/// Handle hover state changes with debouncing
|
||||||
private func handleHover(_ hovering: Bool) {
|
private func handleHover(_ hovering: Bool) {
|
||||||
// Don't process events if we're already transitioning
|
hoverTask?.cancel()
|
||||||
if isHoverStateChanging { return }
|
|
||||||
|
|
||||||
// Cancel any pending tasks
|
|
||||||
hoverWorkItem?.cancel()
|
|
||||||
hoverWorkItem = nil
|
|
||||||
debounceWorkItem?.cancel()
|
|
||||||
debounceWorkItem = nil
|
|
||||||
|
|
||||||
if hovering {
|
if hovering {
|
||||||
// Handle mouse enter
|
|
||||||
withAnimation(.bouncy.speed(1.2)) {
|
withAnimation(.bouncy.speed(1.2)) {
|
||||||
isHovering = true
|
isHovering = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only provide haptic feedback if notch is closed
|
|
||||||
if vm.notchState == .closed && Defaults[.enableHaptics] {
|
if vm.notchState == .closed && Defaults[.enableHaptics] {
|
||||||
triggerHapticIfAllowed()
|
triggerHapticIfAllowed()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delay opening the notch
|
guard vm.notchState == .closed,
|
||||||
let task = DispatchWorkItem {
|
!coordinator.sneakPeek.show,
|
||||||
// ContentView is a struct, so we don't use weak self here
|
Defaults[.openNotchOnHover] else { return }
|
||||||
guard vm.notchState == .closed, isHovering else { return }
|
|
||||||
|
|
||||||
// Additional check: don't open if a sneak peek just started showing
|
|
||||||
// to avoid conflicts during system HUD display
|
|
||||||
if coordinator.sneakPeek.show {
|
|
||||||
// Schedule a retry after the sneak peek should be gone (default duration + small buffer)
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 1.8) {
|
|
||||||
if isHovering && vm.notchState == .closed && !coordinator.sneakPeek.show {
|
|
||||||
doOpen()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
doOpen()
|
|
||||||
}
|
|
||||||
|
|
||||||
hoverWorkItem = task
|
hoverTask = Task {
|
||||||
DispatchQueue.main.asyncAfter(
|
try? await Task.sleep(for: .seconds(Defaults[.minimumHoverDuration]))
|
||||||
deadline: .now() + Defaults[.minimumHoverDuration],
|
guard !Task.isCancelled else { return }
|
||||||
execute: task
|
|
||||||
)
|
await MainActor.run {
|
||||||
|
guard self.vm.notchState == .closed,
|
||||||
|
self.isHovering,
|
||||||
|
!self.coordinator.sneakPeek.show else { return }
|
||||||
|
|
||||||
|
self.doOpen()
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Handle mouse exit with debounce to prevent flickering
|
hoverTask = Task {
|
||||||
let debounce = DispatchWorkItem {
|
try? await Task.sleep(for: .milliseconds(100))
|
||||||
// ContentView is a struct, so we don't use weak self here
|
guard !Task.isCancelled else { return }
|
||||||
|
|
||||||
// Update visual state
|
await MainActor.run {
|
||||||
withAnimation(.bouncy.speed(1.2)) {
|
withAnimation(.bouncy.speed(1.2)) {
|
||||||
isHovering = false
|
self.isHovering = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the notch if it's open and no popovers are active
|
if self.vm.notchState == .open && !self.vm.isBatteryPopoverActive {
|
||||||
let hasActivePopovers = vm.isBatteryPopoverActive || vm.isClipboardPopoverActive || vm.isColorPickerPopoverActive || vm.isStatsPopoverActive
|
self.vm.close()
|
||||||
|
}
|
||||||
if vm.notchState == .open && !hasActivePopovers {
|
|
||||||
vm.close()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debounceWorkItem = debounce
|
|
||||||
// Add a small delay to debounce rapid mouse movements
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1, execute: debounce)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue