TaskBar icon popup menu disappears if main app window is not in focus

Hi,

I have an issue with displaying a popup menu for the taskbar icon (on macOS). One of the points of having a taskbar menu is that it allows me to hide the main application window, and I can still control it via this menu. But when the main app window is out of focus the menu closes immediately after opening. I have checked the hide() function, and it seems that the MouseSourceState::checkButtonState function is the culprit, it dismisses the menu if the app window is not in focus.
I thought that this behaviour (hiding main app window while having a taskbar menu) is common on macOS, there are loads of applications working this way, so I’m not sure why this is not supported. Or am I doing something wrong?

Here is the function that causes me the trouble:

void checkButtonState (Point<int> localMousePos, const uint32 timeNow,
                           const bool wasDown, const bool overScrollArea, const bool isOverAny)
    {
        isDown = window.mouseHasBeenOver()
                    && (ModifierKeys::currentModifiers.isAnyMouseButtonDown()
                         || ComponentPeer::getCurrentModifiersRealtime().isAnyMouseButtonDown());

        const auto reallyContained = window.reallyContains (localMousePos, true);

        if (! window.doesAnyJuceCompHaveFocus() && ! reallyContained)
        {
            if (timeNow > window.lastFocusedTime + 10)
            {
                PopupMenuSettings::menuWasHiddenBecauseOfAppChange = true;
                window.dismissMenu (nullptr);
                // Note: This object may have been deleted by the previous call.
            }
        }
        else if (wasDown && timeNow > window.windowCreationTime + 250 && ! isDown && ! overScrollArea)
        {
            if (reallyContained && window.allowMouseUpToTriggerItem())
                window.triggerCurrentlyHighlightedItem();
            else if ((window.mouseHasBeenOver() || ! window.allowMouseUpToTriggerItem()) && ! isOverAny)
                window.dismissMenu (nullptr);

            // Note: This object may have been deleted by the previous call.
        }
        else
        {
            window.lastFocusedTime = timeNow;
        }
    }