Skip to content

Commit

Permalink
Add multiple livestreamer OSX fallback paths. #99
Browse files Browse the repository at this point in the history
  • Loading branch information
bastimeyer committed May 27, 2015
1 parent fc74729 commit de31240
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
"tray-icon": "img/icon-{res}.png",
"tray-icon-osx": "img/icon-osx-{res}{hidpi}.png",
"livestreamer-exec": "livestreamer",
"livestreamer-fallback-path-unix": "/usr/local/bin",
"livestreamer-fallback-paths-unix": [
"/usr/local/bin",
"/Library/Frameworks/Python.framework/Versions/Current/bin"
],
"livestreamer-version-min": "1.11.1",
"livestreamer-validation-timeout": 10000,
"livestreamer-download-url": "https://github.com/chrippa/livestreamer/releases",
Expand Down
32 changes: 19 additions & 13 deletions src/app/controllers/LivestreamerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ define([
* @returns {Promise}
*/
checkLivestreamer: function() {
var path = get( this.settings, "livestreamer" ),
exec = get( this, "config.livestreamer-exec" ),
fb = get( this, "config.livestreamer-fallback-path-unix" );
var path = get( this, "settings.livestreamer" );
var exec = get( this, "config.livestreamer-exec" );
var fb = get( this, "config.livestreamer-fallback-paths-unix" );

// use the default command if the user did not define one
path = path ? String( path ) : exec;
Expand All @@ -236,14 +236,20 @@ define([

// check for the executable
return which( path, execCheck )
// check fallback path
// check fallback paths
.catch(function() {
if ( !isWin ) {
fb = PATH.join( PATH.resolve( fb ), exec );
return stat( fb, execCheck );
var promise = Promise.reject();
if ( isWin || !fb || !fb.length ) {
return promise;
}
return Promise.reject();
})

return fb.reduce(function( promise, path ) {
var check = PATH.join( PATH.resolve( path ), exec );
return promise.catch(function() {
return stat( check, execCheck );
});
}, promise );
}.bind( this ) )
// not found
.catch(function() { throw new NotFoundError(); })
// check for correct version
Expand All @@ -257,10 +263,10 @@ define([
* @returns {Promise}
*/
validateLivestreamer: function( exec ) {
var minimum = get( this, "config.livestreamer-version-min" ),
time = get( this, "config.livestreamer-validation-timeout" ),
defer = Promise.defer(),
spawn = CP.spawn( exec, [ "--version", "--no-version-check" ] );
var minimum = get( this, "config.livestreamer-version-min" );
var time = get( this, "config.livestreamer-validation-timeout" );
var defer = Promise.defer();
var spawn = CP.spawn( exec, [ "--version", "--no-version-check" ] );

function failed( err ) {
spawn = null;
Expand Down

0 comments on commit de31240

Please sign in to comment.