Somehow I got a problem, if I call an application twice or several times but only one instance should be running (which is desired).
First some (probably necessary) background information:
- working on MAC OS X El Capitan (10.11.6)
- I've got an Application made by node.js, electron and build by "npm build -m" (let's call it APP.app)
- I installed the application App.app into program-folder by opening the built dmg-file and move it into the program-folder
- Then I start the application App.app by click on the App.app-icon in program-folder
- The application starts with a visible Window and also has an hidden background process running
- If I close the visible Window, the App.app-Icon remains in the dock (which is okay, since the background-process is still running)
- Now (and this is the difference to the windows build and running in windows), if I click again on the App.app-Icon in the program-folder, I only get a focus on the already running application INSTEAD of opening the window and close the old application (I can see te focus switch/activation by the switching menu name beside the apple-logo on top of the screen; it becomes "App")
-
the closing of the previous running instance is defined in electron code in the init-method as follows:
var shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) { console.info('starting new instance'); initInternal(commandLine); // Someone tried to run a second instance, we should focus our window. var windows = options.closeWindowsOnRestart ? Browser.getAllWindows() : appWindows.slice(); windows.forEach(function (val, index) { val.close(); }); readyCallback(); });
So, I did some homework and could figure out following:
- my App.app-icon-click should look something like
open /Applications/App.app
- with this, I get the same problem as descriped above if I call it again (it only focusses the already opened window)
- Now comes the funny part. If I open the application by calling directly
/Applications/App.app/content/MacOS/App.app
the old application-instance is closed and new App.app-application is started - I read through
open
-manual and could figure out, that if I use the-n
-flag, the application starts succesful a new instance, too. (open /Applications/App.app -n
)
I was wondering WHY? Do you have any clues? What is the difference between open and directly call of the application?
I suggest that the info.pklist in App.app-package is making the open-call different to the direct call of App.app.
BTW: Unfortunately I already tried to add try-catch-blocks to debug the problem, but open
does not give an output to terminal, it just opens the call whereas the direct call does not throw an error and everything works fine. Anyway, I believe it's more a MAC OS X problem than an App.app-problem.
Hopefully there's somebody with same problems and a solution for me
Don't hesitate to ask for more details, if needed.
via Markus G.
No comments:
Post a Comment