@@ -8,6 +8,10 @@ import Foundation
88import SwiftUI
99import XcodeInspector
1010
11+ #warning("""
12+ TODO: This part is too messy, consider break ing it up, let each window handle their own things
13+ """ )
14+
1115actor WidgetWindowsController: NSObject {
1216 let userDefaultsObservers = WidgetUserDefaultsObservers()
1317 var xcodeInspector: XcodeInspector { .shared }
@@ -419,7 +423,8 @@ extension WidgetWindowsController {
419423 0
420424 } else if previousAppIsXcode {
421425 if windows. chatPanelWindow. isFullscreen,
422- windows. chatPanelWindow. isOnActiveSpace {
426+ windows. chatPanelWindow. isOnActiveSpace
427+ {
423428 0
424429 } else {
425430 1
@@ -513,7 +518,7 @@ extension WidgetWindowsController {
513518 )
514519
515520 updateWindowLocationTask = Task {
516- try await Task . sleep ( nanoseconds: UInt64 ( delay * 1_000_000_000 ) )
521+ try await Task . sleep ( nanoseconds: UInt64 ( delay * 500_000_000 ) )
517522 try Task . checkCancellation ( )
518523 await update ( )
519524 }
@@ -580,9 +585,8 @@ extension WidgetWindowsController {
580585 func handleXcodeFullscreenChange( ) async {
581586 let activeXcode = await XcodeInspector . shared. safe. activeXcode
582587
583- let isFullscreen = if let xcode = activeXcode? . appElement,
584- let xcodeWindow = xcode. focusedWindow
585- {
588+ let xcode = activeXcode? . appElement
589+ let isFullscreen = if let xcode, let xcodeWindow = xcode. focusedWindow {
586590 xcodeWindow. isFullScreen && xcode. isFrontmost
587591 } else {
588592 false
@@ -598,7 +602,7 @@ extension WidgetWindowsController {
598602 $0. send ( . didChangeActiveSpace( fullscreen: isFullscreen) )
599603 }
600604
601- if windows. fullscreenDetector. isOnActiveSpace, isFullscreen {
605+ if windows. fullscreenDetector. isOnActiveSpace, xcode ? . focusedWindow != nil {
602606 windows. orderFront ( )
603607 }
604608 }
@@ -818,7 +822,9 @@ public final class WidgetWindows {
818822 toastWindow. orderFrontRegardless ( )
819823 sharedPanelWindow. orderFrontRegardless ( )
820824 suggestionPanelWindow. orderFrontRegardless ( )
821- if chatPanelWindow. level. rawValue > NSWindow . Level. normal. rawValue {
825+ if chatPanelWindow. level. rawValue > NSWindow . Level. normal. rawValue,
826+ store. withState ( { !$0. chatPanelState. isDetached } )
827+ {
822828 chatPanelWindow. orderFrontRegardless ( )
823829 }
824830 }
0 commit comments