Hello.
I'm trying to change my SwiftUI Mac app icon's menu in the Dock, using the NSApplicationDelegate's applicationDockMenu(_ : ) function.
However, it does not work: The delegate function is only called once, randomly after launch, and then never again, and it will not show any items in that menu I return. When I right-click the app in the Dock, only the macOS-supplied items are shown, and my App delegate function is not called.
Here's the code I use inside my NSApplicationDelegate:
func applicationDockMenu(_ sender: NSApplication) -> NSMenu? {
let men = NSMenu()
print("applicationDockMenu called")
var it = NSMenuItem(title: "Test1", action: #selector(test(_:)), keyEquivalent: "")
it.target = self
men.addItem(it)
it = NSMenuItem(title: "Test2", action: #selector(test(_:)), keyEquivalent: "")
it.target = self
men.addItem(it)
return men
}
@objc func test(_ sender: NSMenuItem) {
print("application dock menu custom item called")
}
Is there a SwiftUI modifier I should be using instead of the NSApp delegate method, or is this just not supported at this time in SwiftUI Mac apps?
Thank you,
- Matthias