Right, so a few things going on here. My current goal is to create an app which sits in the background listening to midi input. It will have a couple of basic settings which I want to be accessible via a native menu attached to a SystemTrayIconComponent. Sounds doable.
I started by creating an audio application in the Projucer.
Here are my issues:
I don’t need the app to have any form of main window, and no dock icon. It will live entirely in the taskbar, with no main menu. I’m able to remove the dock icon via Process::setDockIconVisible (false) but this still allows the app to be brought to the foreground when the SystemTrayIconComponent is clicked, thus showing a bare bones main menu.
Edit: this is solved by getting rid of the automatically created main document window. Duh.
I’m getting an assert when trying to show the native system tray menu. In my overridden mouseDown method I’m creating a PopupMenu and calling SystemTrayIconComponent::showDropdownMenu. The assert I’m getting occurs in juce_mac_MainMenu::createNSMenu, where I’m informed I’m "calling this before making sure the OSX main menu stuff was initialised?" Hmm… I don’t even want a main menu?
I’m not very good at troubleshooting this myself. Someone please help
4 years later, I am having the exact same issue as point number 2 above. I want the menu of my SystemTrayIcon to be “macOS” like, i.e. same as other apps. I believe using the SystemTrayIconComponent::showDropdownMenu() is the way to do this, but there are no examples using it.
Taking the DemoRunner example and changing these lines in Main.cpp at line 70:
m.addItem ("Quit", DemoTaskbarComponent::menuInvocationCallback);
showDropdownMenu(m);
// and I removed the parameters of menuInvocationCallback()
This hits the jassertfalse in createNSMenu(), line 845 of juce_MainMenu_mac.mm.
Looking at the JUCE code, it seems the JuceMainMenuHandler singleton is never instanciated, except in MenuBarModel::setMacMainMenu(), which I guess I should call somehow?
I am not sure I fully grasp what a MenuBarModel is and why it would be nedded for the SystemTrayIcon menu? Could someone point me to the right direction?
Ok, just FYI if someone has the same issue, I managed to get it to work.
I guess the idea is if you are using the system tray with a native macOS menu, you should also configure the native macOS menu on the top left of the screen, fair enough.
But if like me you are not using the menus at all, only the system tray one, then you can simply instanciate a dummy MenuBarModel in your application and call MenuBarModel::setMacMainMenu() with it.
The tray icon does not respond every single time it is clicked, in fact it precisely responds 50% of the time. Testing other mac apps, they do not have that problem. Checking in the code, it seems mouseDown() is only called 1 out of 3 times:
1st click: mouseDown() is called, menu appears
2nd click: menu disappears, mouseDown() is not called (that one makes sense)
3rd click: nothing happens, mouseDown() is not called (should be same as 1st)
4th click: same as 1st
and so on
When exiting with Cmd+Q or with the Apple menu on the top left, everything is fine. But when exiting with the tray icon, the program hangs until it is clicked again. The exit callback calls JUCEApplication::getInstance()->systemRequestedQuit();, which enda the message dispatch loop by calling shutdownNSApp(); at juce_MessageManager_mac.mm:352. But then the program is stuck in [NSApp run];
of runDispatchLoop() (same file at line 335)
The two issues are clearly related, because the second does not happen everytime, depending on whether we are on the click that does not work or not.