Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App open event is returning a string of arguments instead of an array (like App.argv) #2068

Open
ConcurrentHashMap opened this issue Jul 12, 2014 · 5 comments
Assignees

Comments

@ConcurrentHashMap
Copy link

As described here, the open event for gui.App will return the full command line of the second call.

I tried to parse the commandline, but experienced a strange behavior:

// Using 'open' event listener
gui.App.on('open', function(cmdline) {
  console.log('command line: ' + cmdline[1]);
  console.log(typeof cmdline);
  // called with nw.exe --some-test-parameter
  // output: 
  // 'command line: w'
  // string
});

So, this seems to return a string, which can't be accessed directly.
In contrast, let's try the equal thing with gui.App.argv:

// Using gui.App.argv
  console.log(gui.App.argv[1]);
  console.log(typeof gui.App.argv);
  // called with nw.exe --some-test-parameter
  // output: 
  // 'command line: --some-test-parameter'
  // object
});

To be more in line with gui.App.argv (which does return an array object), I would suggest, that the open event should also return an array instead of a string, which makes absolutely sense in my opinion, because a string isn't directly usable without further parsing.

Tested with current v0.10.0-rc1 on Windows.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@nwjs-bot
Copy link

This should be working with latest version now.

In 0.13 we changed to an optimized architecture so more features can be supported, see http://nwjs.io/blog/whats-new-in-0.13/ and it's good for keeping up with Chromium upstream -- we released with Node.js v6.0 and new Chromium versions within 1 day after upstream release.

The new version would fixed many issues reported here and we're scrubbing them. This issue is closed as we believe it should be fixed. Please leave a message if it isn't and we'll reopen it.

@mauvilsa
Copy link

This issue has not been resolved yet, so I would say it should be reopened.

In the documentation (http://docs.nwjs.io/en/latest/References/App/#event-openargs) it does say that the open event returns an string, but I agree this is not too useful. In a test I did in OS X, this string included "--user-data-dir=... --no-sandbox --flag-switches-begin --flag-switches-end --nwapp=...', so parsing it is not as simple as splitting the string. Maybe you could add a function for parsing the args string, so that it gets filtered and is returned as an array analogous to App.argv.

@rogerwang rogerwang reopened this Aug 29, 2016
ghostoy pushed a commit to ghostoy/nw.js that referenced this issue Sep 1, 2016
test case: test/sanity/app-open-event
issue: nwjs#2068
ghostoy pushed a commit to ghostoy/chromium.src that referenced this issue Sep 1, 2016
ghostoy pushed a commit to ghostoy/chromium.src that referenced this issue Sep 1, 2016
test case: test/sanity/app-open-event
fixed nwjs/nw.js#2068
ghostoy pushed a commit to ghostoy/chromium.src that referenced this issue Sep 1, 2016
test case: test/sanity/app-open-event
fixed nwjs/nw.js#2068
@ghostoy
Copy link
Member

ghostoy commented Sep 6, 2016

@mauvilsa I have PRs for sending original command line parameters as a string to App.open event. So it will be compatible with previous versions of NW.js. And it will be easy to parse the parameters with some libraries or write your own.

@ghostoy ghostoy added the bug label Sep 8, 2016
@jonwwilkes
Copy link

@mauvilsa Not sure I understand the response. After the PR gets merged, will the argument to App.open be a string or an array?

Also, I just started using the "open" event so I don't know what the backwards-compatibility entails. For example, currently the nw.js app bundle "open" argv string is a "file://" uri with the path of the file that was clicked. Will your PR change that?

@ghostoy
Copy link
Member

ghostoy commented Nov 14, 2016

It will still be a string to be backward compatible with previous versions.

For example, if you start a second instance with nw --foo bar, the args you get is path/to/nw --foo bar, which is the same as 0.12 or earlier versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants