I want to be able to show a context menu when I right click my MenubarExtra
app, similar to the Figma app behaviour for macOS:
Note that the left clic is showing the actual MenubarExtra window.
The closest solution would be using MenuBarExtraAccess.
You can directly access the NSStatusItem via
.menuBarExtraAccess(isPresented: $isMenuPresented) { statusItem in // <-- the magic ✨
// access status item or store it in a @State var
}
and implement a right-click listener with:
// MARK: Right-mouse icon click
NSEvent.addLocalMonitorForEvents(matching: .rightMouseDown) { [weak self] event in
if event.window == self?.statusItem.button?.window {
WLLNotificationCenter.Keys.statusbarDidClick.send(.rightMouseClicked)
let menu = StatusBarContextMenu()
menu.popUp()
}
return event
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With