anotherInstanceStarted not getting called on MacOS

anotherInstanceStarted gets called on Windows but not on MacOS

MacOS Montaray 12.1 beta
JUCE development branch: ea92834845e1a55f1b840cf45111fc005742764e

In general it’s helpful if you describe the exact steps you took to trigger the problem when reporting issues. At the moment it’s not clear in which scenarios anotherInstanceStarted is/isn’t being called, so I’m not sure if it’s working as intended.

In the ApplicationBase header, we find this documentation for moreThanOneInstanceAllowed():

If your application class returns true for this, more than one instance is permitted to run (except on the Mac where this isn’t possible).

And indeed, when I try to launch any app multiple times on mac, the existing instance is brought to the foreground instead.

On mac, it looks like anotherInstanceStarted is called when double-clicking a file of a type associated with the application in the Finder (e.g. double-clicking a “.jucer” file will call anotherInstanceStarted in a running instance of the Projucer).

Sorry, I try to be more clear in my steps.

It is when trying to launch the application a second time that the anotherInstanceStarted is not getting called on MacOS.

I have moreThanOneInstanceAllowed returning false

What I’m trying to do is that If the user have the app hidden (removeFromDesktop) I would like to when the user tries to open a new instance of the app the allready running app should make itself visible.

I think the behaviour you described should happen automatically. At least, if I open the Projucer, hide its windows using the dock menu, and then try to launch the app again, then the hidden window becomes visible. The hidden window also becomes visible if I double-click a .jucer file in the Finder.

This happens for any app on macOS, I suspect that macOS is dealing with this scenario and just un-hiding the app without trying to start another instance, thus anotherInstanceStarted not being called would be quite logical under macOS in this situation. I would imagine that Windows is not behaving like this quite on purpose and just tries to start another instance if you select it from the Start menu, which feels kind of logical really anyway, if you wanted to just un-hide it you would click on the Task Bar for that particular app; Windows is respecting what the user did, which is explicitly ask to start another instance.

2 Likes