Giter Site home page Giter Site logo

Comments (8)

sindresorhus avatar sindresorhus commented on July 26, 2024

Yeah, currently not possible. I hadn't thought of that use-case.

How about this?

var close = opn('http://sindresorhus.com');

close();

Suggestions on a better API welcome.

from open.

sbruchmann avatar sbruchmann commented on July 26, 2024

I tried to implement it by replacing execFile with spawn; Then I was able to kill the child process with signals (SIGINT, SIGTERM, …), but the actual application wasn’t terminated.

After a quick research, it looks like there’s no easy way to achieve this.

Leaving this open for further discussion.

from open.

watson avatar watson commented on July 26, 2024

I've been toying with the same issue. How about allowing the user to provide a options hash with { wait: false } to override the default behaviour of waiting if opn is called with a callback?

In that case it should just call the callback once the child processes returns from opening the URL.

I can make a pull request if you'd like

from open.

sindresorhus avatar sindresorhus commented on July 26, 2024

@watson 👍 Sounds like a better behaviour than the current way :)

from open.

watson avatar watson commented on July 26, 2024

@sindresorhus Currently the api for the opn function is: opn(target, [app], [callback]). I think it would be too complicated to both understand and implement if we added an options hash between the app and the callback argument.

But since the app argument is seldom used, couldn't we then just make that part of the options hash? I.e. opn(target, [options], [callback]), where options have the following optional properties:

{
  app: "...", // default is platform dependent
  wait: false // default is true if a callback is also given
}

from open.

watson avatar watson commented on July 26, 2024

That would of cause be a breaking change, which I would rather not introduce... but we could of cause detect if it was given a string and fall back to the old behaviour - or just bump the major version? Let me know what you think

from open.

sindresorhus avatar sindresorhus commented on July 26, 2024

opn(target, [options], [callback]) looks good to me.

I'm fine with breaking backwards compat in a major as I doubt the app feature is used much.

from open.

watson avatar watson commented on July 26, 2024

@sindresorhus ^ here you go - let me know what you think :)

from open.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.