Reputation: 2464
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.
Upvotes: 4
Views: 495
Reputation: 926
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
}
Upvotes: 2