URL::launchInDefaultBrowser fix to work when URL::isLocalFile()

Hi Juce Team !
I hope you are all right

Note that URL::launchInDefaultBrowser does not seems to work when URL::isLocalFile

It seems this is because “file://c:/Program Files/xxxx” URL
use escape sequences “file%3A//c%3A/Program%20%Files/xxxx” for Process::openDocument calls.

I do not know if other OS nativelly support them, but to fix it on Window System I just patch juce_URL.cpp like this:

bool URL::launchInDefaultBrowser() const
{
    if (isLocalFile()) // Patch here
        return juce::Process::openDocument(getLocalFile().getFullPathName(), {});
    
    auto u = toString (true);

    if (u.containsChar ('@') && ! u.containsChar (':'))
        u = "mailto:" + u;

    return Process::openDocument (u, {});
}

Maybe this can be merged in your code base?

Hoping this can helps

Thanks for your concern about this.

All the best.

1 Like