MacOS app as background process with system tray icon and native menu…

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:

  1. 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.

  2. 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?

  3. I’m not very good at troubleshooting this myself. Someone please help :slight_smile:

Thanks in advance!

Hi :slight_smile:

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 (1, "Quit");
         m.showMenuAsync (PopupMenu::Options(),
                          ModalCallbackFunction::forComponent (menuInvocationCallback, this));

changed to

         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?

Thank you!

Simon

PS: not sure if this is fully related, but there was a similar issue in the past: SystemTrayIconComponent OSX native menus broken in 5.00 working in 4.3.1 ?