Reputation: 753
I have created a menu bar app for Mac. I want to open the app when clicking on menu bar icon. After updating the OS to Ventura (13.4 (22F66)) I am observing an issue where the NSWindowController is getting displayed on launching the app.
I was able to dismiss the window by adding this flag but now it's not working anymore.
Now I am seeing an error in console on launching the app.
[Window] Warning: Window NSWindow 0x119e17510 ordered front from a non-active application and may order beneath the active application's windows.
class AppDelegate: NSObject, NSApplicationDelegate {
let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.squareLength)
func applicationDidFinishLaunching(_ aNotification: Notification) {
statusItem.button?.image = NSImage(systemSymbolName: "book", accessibilityDescription: "Open")
statusItem.button?.toolTip = "Demo"
statusItem.button?.target = self
statusItem.button?.action = #selector(showSettings)
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true
}
@objc func showSettings() {
let storyboard = NSStoryboard(name: "Main", bundle: nil)
guard let vc = storyboard.instantiateController(withIdentifier: "ViewController") as? ViewController else {
fatalError("Unable to find ViewController in the storyboard.")
}
guard let button = statusItem.button else {
fatalError("Couldn't find status item button.")
}
let popoverView = NSPopover()
popoverView.contentViewController = vc
popoverView.behavior = .transient
popoverView.show(relativeTo: button.bounds, of: button, preferredEdge: .maxY)
}
}
Upvotes: 1
Views: 105