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
{
DemoTaskbarComponent()
{
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.
Process::makeForegroundProcess();
startTimer (50);
}
// This is invoked when the menu is clicked or dismissed
static void menuInvocationCallback (int chosenItemID, DemoTaskbarComponent*)
{
if (chosenItemID == 1)
JUCEApplication::getInstance()->systemRequestedQuit();
}
void timerCallback() override
{
stopTimer();
PopupMenu m;
m.addItem (1, "Quit");
// It's always better to open menus asynchronously when possible.
m.showMenuAsync (PopupMenu::Options(),
ModalCallbackFunction::forComponent (menuInvocationCallback, this));
}
};