fawave_desktop icon indicating copy to clipboard operation
fawave_desktop copied to clipboard

node-webkit how to

Open fengmk2 opened this issue 12 years ago • 2 comments

How to

  • How to open a url in my current browser?
  • How to let node-webkit comunicate with browser? example get the infomation about the current browser visit page url and title.
  • How to let node-webkit application window come to the front when it start?
  • How can I package the app and distribute it?

node-webkit google group about how to

Answer

  • How to open a url in my current browser?

You can use node's child_process module to open the open command, and here is an example: https://github.com/zcbenz/nw-file-explorer/blob/master/node_modules/shell.js

var child_process = require('child_process');

var cmd;
if (process.platform === 'win32') {
  cmd = 'start';
} else if (process.platform === 'linux') {
  cmd = 'xdg-open';
} else if (process.platform === 'darwin') {
  cmd = 'open';
}

exports.open = function (uri) {
  child_process.exec(cmd + ' "' + uri + '"');
};
  • How to let node-webkit comunicate with browser? example get the infomation about the current browser visit page url and title.

It's different on different browsers, but the general way is:

  1. make node-webkit listen at a port and receive commands
  2. write a small program that take browser's url and title and send them into the port that node-webkit is listening
  3. on safari add that small program to the share button (I'm not sure how to); on opera write a custom button. You have to find out how on different browsers.
  • How to let node-webkit application window come to the front when it start?

Use window.focus();

  • How can I package the app and distribute it?

Read https://github.com/rogerwang/node-webkit/wiki/How-to-package-and-distribute-your-apps

fengmk2 avatar Oct 05 '12 15:10 fengmk2

window.focus(); not work on my mbp.

fengmk2 avatar Oct 05 '12 15:10 fengmk2

windows open: http://stackoverflow.com/questions/118748/windows-console-command-to-open-multiple-pages-in-internet-explorer-7

fengmk2 avatar Oct 07 '12 09:10 fengmk2