@@ -79,6 +79,8 @@ public struct WidgetFeature: ReducerProtocol {
7979 )
8080 }
8181 }
82+
83+ var lastUpdateWindowOpacityTime = Date ( timeIntervalSince1970: 0 )
8284
8385 public init ( ) { }
8486 }
@@ -109,6 +111,7 @@ public struct WidgetFeature: ReducerProtocol {
109111 case updateWindowLocation( animated: Bool )
110112 case updateWindowOpacity
111113 case updateFocusingDocumentURL
114+ case updateWindowOpacityFinished
112115
113116 case panel( PanelFeature . Action )
114117 case chatPanel( ChatPanelFeature . Action )
@@ -513,9 +516,12 @@ public struct WidgetFeature: ReducerProtocol {
513516 case . updateWindowOpacity:
514517 let isChatPanelDetached = state. chatPanelState. chatPanelInASeparateWindow
515518 let hasChat = !state. chatPanelState. chatTabGroup. tabInfo. isEmpty
516- return . run { _ in
517- try await mainQueue. sleep ( for: . seconds( 0.2 ) )
518- Task { @MainActor in
519+ let shouldDebounce = Date ( ) . timeIntervalSince ( state. lastUpdateWindowOpacityTime) < 1
520+ return . run { send in
521+ if shouldDebounce {
522+ try await mainQueue. sleep ( for: . seconds( 0.2 ) )
523+ }
524+ let task = Task { @MainActor in
519525 if let app = activeApplicationMonitor. activeApplication, app. isXcode {
520526 let application = AXUIElementCreateApplication ( app. processIdentifier)
521527 /// We need this to hide the windows when Xcode is minimized.
@@ -564,8 +570,14 @@ public struct WidgetFeature: ReducerProtocol {
564570 }
565571 }
566572 }
573+ _ = await task. value
574+ await send ( . updateWindowOpacityFinished)
567575 }
568576 . cancellable ( id: DebounceKey . updateWindowOpacity, cancelInFlight: true )
577+
578+ case . updateWindowOpacityFinished:
579+ state. lastUpdateWindowOpacityTime = Date ( )
580+ return . none
569581
570582 case . circularWidget:
571583 return . none
0 commit comments