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

Fails to find livestreamer #24

Closed
Nevon opened this issue Oct 26, 2014 · 7 comments
Closed

Fails to find livestreamer #24

Nevon opened this issue Oct 26, 2014 · 7 comments

Comments

@Nevon
Copy link

Nevon commented Oct 26, 2014

livestreamer-twitch-gui fails to find my livestreamer installation in OSX when using installed version. As you can see, livestreamer is in my path:

➜  ~  which livestreamer
/usr/local/bin/livestreamer
➜  ~  ls -l /usr/local/bin |grep livestreamer
-rwxr-xr-x  1 root        admin    289 Oct 17 20:22 livestreamer
➜  ~ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/opt/go/libexec/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/opt/go/libexec/bin

If I launch livestreamer-twitch-gui by cloning the repo, running the build command and then manually running the application from the src directory, it finds the livestreamer binary:

➜  livestreamer-twitch-gui git:(master) ./build/releases/livestreamer-twitch-gui/osx/livestreamer-twitch-gui.app/Contents/MacOS/node-webkit src
2014-10-26 10:34:37.280 node-webkit[10474:1002893] Internals of CFAllocator not known; out-of-memory failures via CFAllocator will not result in termination. http://crbug.com/45650
[10474:1026/103437:ERROR:breakpad_mac.mm(238)] Breakpad initializaiton failed
2014-10-26 10:34:37.438 node-webkit Helper[10475:1002962] Internals of CFAllocator not known; out-of-memory failures via CFAllocator will not result in termination. http://crbug.com/45650
2014-10-26 10:34:37.701 node-webkit Helper[10476:1002995] Internals of CFAllocator not known; out-of-memory failures via CFAllocator will not result in termination. http://crbug.com/45650
[10474:1026/103437:INFO:CONSOLE(1)] ""process.mainModule.filename: /index.html"", source: process_main (1)

I figured it was because installed GUI apps launched from spotlight or the dock don't have /usr/local/bin in their PATH by default, but launching the installed application from the terminal doesn't work either:

➜  livestreamer-twitch-gui git:(master) open ~/Applications/Livestreamer\ Twitch\ GUI.app

Manually setting the path in the livestreamer-twitch-gui settings does resolve the issue, but it's nevertheless strange that the binary isn't found when running the installed version (it is the latest, btw). The only thing I can think of is that maybe process.env.path is different for the installed version, but I don't see why it would be.

@bastimeyer
Copy link
Member

Sounds strange...
Could you please check the value of the process.env.PATH, process.env.Path, process.env.path variables? Also see this line...
Start the application with --remote-debugging-port=8888 and open up http://localhost:8888 to do this.

The node-webkit version has changed since the v0.5.0 release from 0.10.1 to 0.10.4, so the issue might be in the old nw version.

@Nevon
Copy link
Author

Nevon commented Oct 26, 2014

I'm trying to get the value of process.env.PATH et. al. but requirejs minifies the file so that I can't get in to place a breakpoint (even after trying chrome's formatter), and even littering which.js with console.log statements doesn't seem to output anything. I must be something wrong. How are you supposed to work on this application? It seems kind of weird to have to create a build and run the node-webkit binary from inside the app bundle on the src directory, but I can't seem to find any obvious grunt tasks to launch it with debugging set up.

@Nevon
Copy link
Author

Nevon commented Oct 26, 2014

Alright, I installed the nodewebkit package globally and tried running the src directory with it. Lots of resources are broken and stuff, but I did get the value of PATHS:

0: "/usr/local/bin"
1: "/usr/bin"
2: "/bin"
3: "/usr/sbin"
4: "/sbin"
5: "/usr/local/opt/go/libexec/bin"
6: "/usr/bin"
7: "/bin"
8: "/usr/sbin"
9: "/sbin"
10: "/usr/local/bin"
11: "/usr/local/opt/go/libexec/bin"

As suspected, running the latest version from the repo does have the correct path. I'm trying to check the values from the installed version, but since I can't seem to get any breakpoints in there, it's proving to be challenging.

EDIT: Got the info by modifying the minified source in the installed app bundle.

0: "/usr/bin"
1: "/bin"
2: "/usr/sbin"
3: "/sbin"

I guess this might have been a bug with the old version of node-webkit, then.

@bastimeyer
Copy link
Member

I've just tested it with all v0.10.x node-webkit versions and it's still not working properly. 😞

Like you've mentioned, it's working after launching the application via the bash and using the open command, but it doesn't if you open it via the finder or dock. The value of process.env.PATH then is /usr/bin:/bin:/usr/sbin:/sbin instead of the expected /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin.

So is this really a node-webkit bug or is this intended behavior of OSX? (I don't use it, so I don't know...)
How can this be fixed? Simply adding the /usr/local/bin path could make it work, but this is a bit dirty.

@Nevon
Copy link
Author

Nevon commented Oct 26, 2014

It seems that apps launched through spotlight or the dock don't read environment variables from the normal places (.profile, .bash_profile, etc.), so $PATH is just set to whatever the default is. I guess it's intended (why, I don't know...), not a bug.

However, from what I've been able to gather from some quick googling, it seems you can set environment variables from within app bundles by declaring them in an Info.plist file. For node-webkit apps, that file should be in Contents/Info.plist, more info here. This answer on Stack Overflow mentions how to set the PATH variable.

The issue is that there's no way to read the path from any of the sane places, so I'm guessing the least intrusive way would be to create a list of common places where it could be installed and add that to a separate environment variable (LIVESTREAMER_TWITCH_GUI_PATH or something) and read that if available.

Now, I think you'd still want to read from the normal path as well, so maybe this line will have to change, since it only reads from the first available environment variable:

PATH = process.env.PATH || process.env.Path || process.env.path || "."

Maybe instead you could read from all of them (plus your own), filter out the duplicates and go from there?

I'd be willing to help you out, if I knew how the development workflow was set up, but I'm going to be very busy all week, so I'll likely not have any opportunity until next weekend. I'll be checking my notifications though, so I'll try to be around to test things or maybe try implementing something as soon as I have the time.

@bastimeyer
Copy link
Member

Thanks for offering your help, much appreciated!

I think the right way of fixing this issue would be changing the Info.plist and adding the needed LSEnvironment data. I don't want to change the code itself, because it's just an osx related issue and things don't need to be unnecessarily messy here.
It's a little bit sad that you can't read the user specific $PATH and prepend/append your path to it. But I think /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin should be good enough, since we're just looking for the livestreamer executable.

The problem I ran into so far is the way node-webkit-builder deals with a custom plist. You're able to define a custom one instead of generating one off the blank node-webkit app, but then you also need to provide all the other stuff. That's not what I want to do, I just want to add one (nested) key-value pair. So I guess I need to make another pull request over there.

@bastimeyer
Copy link
Member

I'm still waiting for a merge at nwutils/nw-builder#96...
My forked repositories will be used as build dependency until then.

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

No branches or pull requests

2 participants