Hello,
So im trying to build a node-webkit app where there can only be one instance of it running. The package manifest has a property called single-instance which can be set to true (the default) to prevent multiple instances of an app or false to allow multiple instances.
Here is my app for reference:
app/package.json
"main": "spawn-test/index.html",
"node-main": "spawn-test/index.js",
app/spawn-test/index.html
var gui = require('nw.gui');
var win = gui.Window.get();
console.log('Started with args: '+gui.App.argv.join(' '));
gui.App.on('open', function(args) {
console.log('Message received: '+args);
app/spawn-test/index.js
Now if I package this into a app.nw bundle (the renamed zip) and launch it from two terminal tabs like so it opens two instances:
Now, on windows what happens is the second instance is terminated and the "open" event is emit on the gui.App object (I need this behaviour on Mac OSX).
This seems to be the incorrect behaviour on Mac OSX.
So I have done some further testing on the Mac and if i bundle the app into a Mac ".app" bundle launching the first time it opens as expected. If you double click the app the second time, it simply moves the original to the foreground, and does not not emit an open event on the original which isn't quite the same as how Windows behaves.
If i launch the first instance by double clicking the .app bundle and then the second instance by running:
It works fine.
I assume then that node-webkit is relying on Mac OSX app bundles to enforce the single-instance behaviour?
These tests have been performed with both 0.8.4 and the 0.9.0 rc1 builds currently on the node-webkit github readme.
What I'm planning to build will be a background app which supports an existing app, so ideally I wouldn't use a mac app bundle and it needs to behave like the windows one to prevent multiple helpers opening. Does anybody know how I would go about making the mac behave like the windows counterpart?
Any help would be much appreciated