blob: ad561050e63bc71b0e891ade96bdbd3b75e1bac1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
import SwiftUI
private class NSWindowAccessorView: NSView {
let executeBlock: (_ window: NSWindow?) -> Void
init(_ inConfigFunction: @escaping (_ window: NSWindow?) -> Void) {
executeBlock = inConfigFunction
super.init(frame: NSRect())
}
required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") }
public override func viewDidMoveToWindow() {
super.viewDidMoveToWindow()
executeBlock(self.window) // We pass it through even if it is nil.
}
}
public struct NSWindowAccessor: NSViewRepresentable {
var configCode: (_ window: NSWindow?) -> Void
public init(_ configCode: @escaping (_: NSWindow?) -> Void) { self.configCode = configCode }
public func makeNSView(context: Context) -> NSView { return NSWindowAccessorView(configCode) }
public func updateNSView(_ nsView: NSView, context: Context) {}
}
|