Skip to content

Commit

Permalink
Fix error logic in LivestreamerController
Browse files Browse the repository at this point in the history
  • Loading branch information
bastimeyer committed Sep 14, 2015
1 parent cdd1e4e commit 837e57e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
42 changes: 27 additions & 15 deletions src/app/controllers/LivestreamerController.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ define([
Warning.prototype = merge( new Error(), { name: "Warning" } );


function execCheck( stat ) {
// octal: 0111
return isWin || ( stat.mode & 73 ) > 0;
}


// we need a common error parsing function for stdout and stderr, because
// livestreamer is weird sometimes and prints error messages to stdout instead... :(
function parseError( data ) {
Expand Down Expand Up @@ -129,17 +135,22 @@ define([
})
// validate configuration and get the exec command
.then( this.checkLivestreamer.bind( this ) )
// launch the stream
.then( this.launchLivestreamer.bind( this, livestreamer, true ) )
// setup stream refresh interval
.then( this.refreshStream.bind( this, livestreamer ) );
.then(
// launch the stream
this.launchLivestreamer.bind( this, livestreamer, true ),
// show error message
this.onStreamFailure.bind( this, livestreamer )
);
},

onStreamSuccess: function( livestreamer, firstLaunch ) {
set( livestreamer, "success", true );

if ( !firstLaunch ) { return; }

// setup stream refresh interval
this.refreshStream( livestreamer );

// automatically close modal on success
if ( get( this, "settings.gui_hidestreampopup" ) ) {
this.send( "close" );
Expand Down Expand Up @@ -192,26 +203,27 @@ define([
var path = get( this, "settings.livestreamer" );
var exec = get( this, "metadata.config.livestreamer-exec" );
var fb = get( this, "metadata.config.livestreamer-fallback-paths-unix" );
var livestreamer;

// use the default command if the user did not define one
path = path ? String( path ) : exec;
path = String( path ).trim();

// check for invalid values first
if ( path.indexOf( exec ) === -1 ) {
// use the default command if the user did not define one
if ( !path.length ) {
livestreamer = exec;
// otherwise check for containing executable name
} else if ( path.indexOf( exec ) !== -1 ) {
livestreamer = path;
} else {
return Promise.reject( new NotFoundError() );
}

function execCheck( stat ) {
// octal: 0111
return isWin || ( stat.mode & 73 ) > 0;
}

// check for the executable
return which( path, execCheck )
return which( livestreamer, execCheck )
// check fallback paths
.catch(function() {
var promise = Promise.reject();
if ( isWin || !fb || !fb.length ) {
// ignore fallbacks if custom path has been set
if ( path || isWin || !fb || !fb.length ) {
return promise;
}

Expand Down
2 changes: 1 addition & 1 deletion src/templates/modals/livestreamer.html.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
{{else if (is-equal error.name "VersionError")}}
{{#modal-header}}Error: Invalid Livestreamer version{{/modal-header}}
{{#modal-body class="error"}}
Your version v{{versionCurrent}} doesn't match the min. requirements (v{{versionMin}}).
Your version v{{error.version}} doesn't match the min. requirements (v{{metadata.config.livestreamer-version-min}}).
{{/modal-body}}
{{else if (is-equal error.name "UnableToOpenError")}}
{{#modal-header}}Error: Unable to open stream{{/modal-header}}
Expand Down

0 comments on commit 837e57e

Please sign in to comment.