Demo Runner bug - unresponsive system tray icon on macOS

I encountered an issue when running the Demo Runner app on Mac: while having the main DemoRunner window reduced and another focused app in fullscreen mode, the Demo Runner system tray icon becomes un-responsive (clicking on the icon will close the expanded system tray and set the focus back to the full screen app). I tried to solve the issue myself but with no luck at the moment. I attach the code deals with the system tray icon:

One more question: do we still need to use timers when implementing a system tray icon or has the issue been solved with the newer versions of macOS?

JUCE version: 6.0.8
macOS version: 11.4

Thanks in advance

 // Just add a simple icon to the Window system tray area or Mac menu bar..
 struct DemoTaskbarComponent  : public SystemTrayIconComponent,
                                private Timer
         setIconImage (getImageFromAssets ("juce_icon.png"),
                       getImageFromAssets ("juce_icon_template.png"));
         setIconTooltip ("JUCE demo runner!");

     void mouseDown (const MouseEvent&) override
         // On OSX, there can be problems launching a menu when we're not the foreground
         // process, so just in case, we'll first make our process active, and then use a
         // timer to wait a moment before opening our menu, which gives the OS some time to
         // get its act together and bring our windows to the front.

         startTimer (50);

     // This is invoked when the menu is clicked or dismissed
     static void menuInvocationCallback (int chosenItemID, DemoTaskbarComponent*)
         if (chosenItemID == 1)

     void timerCallback() override

         PopupMenu m;
         m.addItem (1, "Quit");

         // It's always better to open menus asynchronously when possible.
         m.showMenuAsync (PopupMenu::Options(),
                          ModalCallbackFunction::forComponent (menuInvocationCallback, this));

It looks like the menu window will auto-dismiss if the JUCE app is not the foreground process. When the main JUCE app is minimised, Process::makeForegroundProcess() fails to bring the app to the foreground, so the menu immediately hides itself.

Instead of a PopupMenu, it might be possible to get this to work with a custom component which doesn’t require the JUCE process to be in the foreground. Getting this to work with a PopupMenu would probably require changes to the framework. I’ll put this on my backlog, but I’m not sure when I’ll get a chance to look at this properly.

1 Like