single app instance

59 views
Skip to first unread message

Dan Kadera

unread,
May 15, 2013, 4:24:50 PM5/15/13
to appj...@googlegroups.com
Hi all,

I'd like to ask, is it possible to make an app run in single instance? i.e. when I run the app the second time, I'd somehow detect that there is already an instance running and do a different action than the regular startup..
Ideally I'd like to be able to pass some info to the current running instance.

The purpose of this is to enable users of my app to create global (system-wide) shortcuts for some action by using whatever shortcut mechanism / app they like (or their system supports) - they'd create a shortcut which'd run the app with a command-line parameter specifying the action, and the app, seeing that a running instance already exists, would dispatch an event in the already existing instance. I'm, as yet, quite the noob where it comes to node.js, so maybe the answer is obvious; sorry if that is the case. I'd appreciate any and all help.

NB. I'm on Win 7 and the latest package I downloaded seems to still be haunted by a bug which I believe has been already fixed - the background cannot be made transparent. I set the "alpha" property of the frame to true in app.js and applied the appropriate CSS, but the background stays black as night. I tried building AppJS from source and failed miserably, so I'm not sure if the fix should be already present in the version I use, or if it will be part of the next version. I'm running AppJS 0.0.20.

Thanks,
Dan

Simon Horton

unread,
May 15, 2013, 4:28:16 PM5/15/13
to appj...@googlegroups.com
Hi Dan,

You can make nodejs listen to a given port. When you run the app connect to the port and see if anyone is listening. If they are then you could send them a message to the port and then shut down your program.

/Simon


--
You received this message because you are subscribed to the Google Groups "appjs-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to appjs-dev+...@googlegroups.com.
To post to this group, send email to appj...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Dan Kadera

unread,
May 15, 2013, 5:12:50 PM5/15/13
to appj...@googlegroups.com, siho...@gmail.com
Wow, that's a lot simpler than I expected! Thanks a lot for the quick reply! :o)

Kevin Ingwersen

unread,
May 15, 2013, 6:07:06 PM5/15/13
to appj...@googlegroups.com
How does one listen on a port o.O?

Simon Horton

unread,
May 15, 2013, 6:08:59 PM5/15/13
to appj...@googlegroups.com
Its quite easy in nodejs. Here is the hello world example from their homepage:-


var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

So that is listening to port 1337.

/Simon

Reply all
Reply to author
Forward
0 new messages