Please adjust access to JUCEApplication::appLock

In order so that i don’t have to have a copy of the code from JUCEApplication::initialiseApp() (specifically, the part that does appLock = new InterProcessLock (“juceAppLock_” + getApplicationName())), I would like to have a little access to the ScopedPointer appLock.

Specifically, when I get an exception and force my app to terminate after launching a second instance with a command line instructing it to show an alert, I would like to release the InterProcessLock by doing

  appLock = 0;
  File::getSpecialLocation (File::currentExecutableFile).startAsProcess (exceptionStringToDisplay);
  Process::terminate ();

Can we please either make appLock protected, or add this routine to JUCEApplication:

void JUCEApplication::releaseAppLock ()
  appLock = 0;


No chance.

Okay, well how about moving this bit into a protected member of JUCEApplication that I can call from my initialise, so that I don’t have to make a copy of it:

#if ! JUCE_IOS
    jassert (appLock == 0); // initialiseApp must only be called once!

    if (! moreThanOneInstanceAllowed())
        appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());

        if (! appLock->enter(0))
            appLock = 0;
            MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);

            DBG ("Another instance is running - quitting...");
            return false;

That code is private because I don’t want people messing about with it or writing hacky bodges that rely on the way it’s implemented.

If you don’t want to use the normal app lock, turn it off and use your own InterprocessLock, then you can do whatever you want with it.

That’s what I"m doing but I don’t understand the “#if ! JUCE_IOS” part…I made a copy of your interprocess lock code and stuck it in my initialise()

Does MacOS prevent apps from launching multiple instances?

Yes. And on iOS the startup is handled in a completely different way altogether. Best to just stick to the public interfaces and don’t go poking around in the implementation.


Will this not work on Mac:

File::getSpecialLocation (File::currentExecutableFile).startAsProcess (exceptionStringToDisplay);


I think that if you launch the .app file, it probably won’t work, but if you launch the actual posix binary, then it might.