Message loop is not exited after stopDispatchLoop until tray icon is clicked again

I am trying to add a tray icon with a popup menu that lets the user close the app, but for some reason the app does not close until the main window or the tray icon is clicked a second time after quit.

I can see that the call to the below method is being made when I choose to quit the app:

void JUCEApplicationBase::quit()

…but the last line in main is not reached until the tray icon is clicked again:

int JUCEApplicationBase::main()
    ScopedJuceInitialiser_GUI libraryInitialiser;
    jassert (createInstance != nullptr);

    const std::unique_ptr<JUCEApplicationBase> app (createInstance());
    jassert (app != nullptr);

    if (! app->initialiseApp())
        return app->shutdownApp();

        // loop until a quit message is received..

    return app->shutdownApp();

This used to work before, and seem to have been introduced in

Minimal example:

Friendly bump :slight_smile:

One way to fix this is to mirror what the DemoRunner does and show the menu asynchronously:

This avoids some problematic modal state.

1 Like