Open polymerchm opened 3 years ago
Yeah, hostWindowForUIWindow()
now returns UINSWindowProxy
on macOS 11. We need to call UINSWindowProxy.attachedWindow
to get the actual window:
extension UIWindow {
var nsWindow: NSObject? {
var nsWindow = Dynamic.NSApplication.sharedApplication.delegate.hostWindowForUIWindow(self)
if #available(macOS 11, *) {
nsWindow = nsWindow.attachedWindow
}
return nsWindow.asObject
}
}
Let me know if it works for you.
Adding the attachedWindow
works on BigSur, but if #available(macOS 11, *)
also resolves to true on Catalina.
I ended up with this for now:
extension UIWindow
{
public var nsWindow: Dynamic
{
if ProcessInfo.processInfo.isOperatingSystemAtLeast(OperatingSystemVersion(majorVersion: 11, minorVersion: 0, patchVersion: 0))
{
return Dynamic.NSApplication.sharedApplication.delegate.hostWindowForUIWindow(self).attachedWindow
}
else
{
return Dynamic.NSApplication.sharedApplication.delegate.hostWindowForUIWindow(self)
}
}
}
The following code (use to position and size the main window after launch) now crashes
delay(0.1) { let ns = self.window?.nsWindow Dynamic(ns!).setFrame(CGRect(200,200,1200,800), display: true) let frame = Dynamic(ns!).frame.asCGRect! let size = frame.size Dynamic(ns!).setAspectRatio(CGSize(1.0, size.height/size.width))
}
with the following error
2020-11-17 21:42:22.832850-0600 ChordCalc Mac[11229:361126] Metal API Validation Enabled WARNING: Trying to access an unrecognized member: UINSWindowProxy.setFrame:display: