statusBarItem?.button?.action = #selector(AppDelegate.togglePopover(_:))
// When starting the app, show the popover. If don't do like this, open the app and shortcuts will not work until click the icon on the menu bar.
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
if let button = self.statusBarItem?.button {
self.popover.show(
relativeTo: button.bounds,
of: button, preferredEdge: NSRectEdge.minY)
}
}
The problem is that if the user hide the menu bar (System Preferences -> Dock & Menu Bar -> Dock & Menu Bar -> Automatically hide and show the menu bar -> checked), the popover will appear on the top left corner of the screen, instead of appearing below the menu bar icon.
The problem is that if the user hide the menu bar (
System Preferences -> Dock & Menu Bar -> Dock & Menu Bar -> Automatically hide and show the menu bar -> checked
), the popover will appear on the top left corner of the screen, instead of appearing below the menu bar icon.Also check https://github.com/zaferarican/menubarpopoverswiftui2/issues/3#issuecomment-894803220