1
votes

In my menu bar app, I have a menu item which opens a window. The window opens in the front with the window behind it remaining the key window.

I can't get window.makeKey() to work unless I run it after a breakpoint. I tried putting the line of code in different places in the window's life cycle and even put it in DispatchQueue.main.asyncAfter(deadline: execute:) and it didn't work.

I have also tried using window.makeKeyAndOrderFront(sender:). The property window.canBecomeKey is true.

1

1 Answers

4
votes

Turns out I needed to put this line in the IBAction for the menu item that opens the window:

NSApplication.shared.activate(ignoringOtherApps: true)

That makes it the key window when it opens, so I don't have to call window.makeKey()