Skip to content

Commit aa1cab5

Browse files
committed
Revert "fix: prevent crash in WindowAccessor by using viewDidMoveToWindow"
This reverts commit 9938a5a.
1 parent 9938a5a commit aa1cab5

File tree

1 file changed

+4
-22
lines changed

1 file changed

+4
-22
lines changed

TablePro/Views/Components/WindowAccessor.swift

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,17 @@
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

109
import SwiftUI
1110

1211
struct 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
}

0 commit comments

Comments
 (0)