Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big Sur breaks code #7

Open
polymerchm opened this issue Nov 18, 2020 · 2 comments
Open

Big Sur breaks code #7

polymerchm opened this issue Nov 18, 2020 · 2 comments

Comments

@polymerchm
Copy link

polymerchm commented Nov 18, 2020

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:

@mhdhejazi
Copy link
Owner

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.

@gabors
Copy link

gabors commented Nov 19, 2020

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)
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants