Skip to content

Commit

Permalink
Add 'detached' option
Browse files Browse the repository at this point in the history
Add option 'detached' to allow the opened app to continue running after the
parent process exits.

in Linux and MacOS if this option is true, the child process `stdio` is
set to 'ignore'.
  • Loading branch information
GAumala committed Mar 5, 2017
1 parent b792b3b commit 5c75e8c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = (target, opts) => {
let appArgs = [];
let args = [];
const cpOpts = {};
cpOpts.detached = opts.detached;

if (Array.isArray(opts.app)) {
appArgs = opts.app.slice(1);
Expand All @@ -29,6 +30,10 @@ module.exports = (target, opts) => {
if (opts.app) {
args.push('-a', opts.app);
}

if (opts.detached) {
cpOpts.stdio = 'ignore';
}
} else if (process.platform === 'win32') {
cmd = 'cmd';
args.push('/c', 'start', '""');
Expand Down Expand Up @@ -56,7 +61,7 @@ module.exports = (target, opts) => {
args = args.concat(appArgs);
}

if (!opts.wait) {
if (!opts.wait || opts.detached) {
// `xdg-open` will block the process unless
// stdio is ignored even if it's unref'd
cpOpts.stdio = 'ignore';
Expand Down
5 changes: 5 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ Specify the app to open the `target` with, or an array with the app and app argu

The app name is platform dependent. Don't hard code it in reusable modules. For example, Chrome is `google chrome` on macOS, `google-chrome` on Linux and `chrome` on Windows.

##### detached

Type: `boolean`<br>

Detachs the opened app from its node.js parent process and ignores parent `stdio` file descriptors so that it may continue to run after the parent exits.

## Related

Expand Down

0 comments on commit 5c75e8c

Please sign in to comment.