Host demo Quit issue

Perhaps considered an edge case… but if you try and Command+Q while the saveIfNeededAndUserAgrees() AlertWindow is open you get an assertion.

By having a private MainHostWindow member variable

bool    tryingToCloseFlag;

intialized to false, then in

bool MainHostWindow::tryToQuitApplication()
{
    if (tryingToCloseFlag)
        return false;
    
    PluginWindow::closeAllCurrentlyOpenWindows();
    
    tryingToCloseFlag = true;

    if (getGraphEditor() == nullptr
         || getGraphEditor()->graph.saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk)
    {
        JUCEApplication::quit();
        return true;
    }
    
    tryingToCloseFlag = false;

    return false;
}

This will stop the assertion… otherwise the AlertWindows stack up and when you quit() some components are going to leak.

Rail

Yeah, it's an edge case that I didn't bother trying to fix in the demo host. Didn't want to over-complicate the code.

Actually, a much better way (and more general-purpose) way to avoid that problem in your real-world app would be to use the trick I do in the Introjucer - have a look at IntrojucerApp::systemRequestedQuit()

Yeah, the problem with that was it closed then re-opens the AlertWindow which is a bad user experience…

perhaps:

bool MainHostWindow::tryToQuitApplication()
{
    if (ModalComponentManager::getInstance()->getNumModalComponents())
        return false;
    
    PluginWindow::closeAllCurrentlyOpenWindows();

    if (getGraphEditor() == nullptr
         || getGraphEditor()->graph.saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk)
    {
        JUCEApplication::quit();
        return true;
    }

    return false;
}

Cheers,

Rail