File tree Expand file tree Collapse file tree 1 file changed +4
-22
lines changed
TablePro/Views/Components Expand file tree Collapse file tree 1 file changed +4
-22
lines changed Original file line number Diff line number Diff line change 33// TablePro
44//
55// Captures the hosting NSWindow from SwiftUI via an invisible NSView.
6- // Uses viewDidMoveToWindow to capture once, avoiding repeated async
7- // dispatches that can race with window deallocation.
6+ // Avoids brittle title-matching or NSApp.keyWindow heuristics.
87//
98
109import SwiftUI
1110
1211struct WindowAccessor : NSViewRepresentable {
1312 @Binding var window : NSWindow ?
1413
15- func makeNSView( context: Context ) -> WindowAccessorView {
16- let view = WindowAccessorView ( )
17- view. onWindowChange = { [ self ] newWindow in
18- self . window = newWindow
19- }
20- return view
21- }
22-
23- func updateNSView( _ nsView: WindowAccessorView , context: Context ) {
24- nsView. onWindowChange = { [ self ] newWindow in
25- self . window = newWindow
26- }
27- }
28- }
29-
30- final class WindowAccessorView : NSView {
31- var onWindowChange : ( ( NSWindow ? ) -> Void ) ?
14+ func makeNSView( context: Context ) -> NSView { NSView ( ) }
3215
33- override func viewDidMoveToWindow( ) {
34- super. viewDidMoveToWindow ( )
35- onWindowChange ? ( window)
16+ func updateNSView( _ nsView: NSView , context: Context ) {
17+ DispatchQueue . main. async { self . window = nsView. window }
3618 }
3719}
You can’t perform that action at this time.
0 commit comments