Improve startup checking

Before this fix, if the daemon wasn't accepting connections
the UI would get an error and then be stuck on the loading screen.

We now check if the daemon is accepting connections first, and then
check for the status.
This commit is contained in:
Job Evers-Meltzer 2017-01-18 09:29:47 -06:00
parent bfbe69a861
commit 2aa10261d9
2 changed files with 37 additions and 28 deletions

View file

@ -14,24 +14,36 @@ var SplashScreen = React.createClass({
} }
}, },
updateStatus: function(was_lagging=false) { updateStatus: function(was_lagging=false) {
lbry.getDaemonStatus((status) => { lbry.getDaemonStatus(this._updateStatusCallback);
if (status.code == 'started') { },
this.props.onLoadDone(); _updateStatusCallback: function(status) {
return; if (status.code == 'started') {
} // Wait until we are able to resolve a name before declaring
// that we are done.
this.setState({ // TODO: This is a hack, and the logic should live in the daemon
details: status.message + (status.is_lagging ? '' : '...'), // to give us a better sense of when we are actually started
isLagging: status.is_lagging, this.setState({
}); details: 'Waiting for name resolution',
isLagging: false
setTimeout(() => {
this.updateStatus(status.is_lagging);
}, 500);
}); });
lbry.resolveName('one', () => {
this.props.onLoadDone();
});
return;
}
this.setState({
details: status.message + (status.is_lagging ? '' : '...'),
isLagging: status.is_lagging,
});
setTimeout(() => {
this.updateStatus(status.is_lagging);
}, 500);
}, },
componentDidMount: function() { componentDidMount: function() {
this.updateStatus(); lbry.connect((connected) => {
this.updateStatus();
});
}, },
render: function() { render: function() {
return <LoadScreen message={this.props.message} details={this.state.details} isWarning={this.state.isLagging} />; return <LoadScreen message={this.props.message} details={this.state.details} isWarning={this.state.isLagging} />;

View file

@ -90,17 +90,18 @@ lbry.call = function (method, params, callback, errorCallback, connectFailedCall
//core //core
lbry.connect = function(callback) lbry.connect = function(callback)
{ {
// Check every half second to see if the daemon's running. // Check every half second to see if the daemon is accepting connections
// Returns true to callback once connected, or false if it takes too long and we give up. // Once this returns True, can call getDaemonStatus to see where
function checkDaemonRunning(tryNum=0) { // we are in the startup process
lbry.daemonRunningStatus(function (runningStatus) { function checkDaemonStarted(tryNum=0) {
lbry.isDaemonAcceptingConnections(function (runningStatus) {
if (runningStatus) { if (runningStatus) {
lbry.isConnected = true; lbry.isConnected = true;
callback(true); callback(true);
} else { } else {
if (tryNum <= 600) { // Move # of tries into constant or config option if (tryNum <= 600) { // Move # of tries into constant or config option
setTimeout(function () { setTimeout(function () {
checkDaemonRunning(tryNum + 1); checkDaemonStarted(tryNum + 1);
}, 500); }, 500);
} else { } else {
callback(false); callback(false);
@ -108,16 +109,12 @@ lbry.connect = function(callback)
} }
}); });
} }
checkDaemonRunning(); checkDaemonStarted();
} }
lbry.daemonRunningStatus = function (callback) { lbry.isDaemonAcceptingConnections = function (callback) {
// Returns true/false whether the daemon is running (i.e. fully conncected to the network), // Returns true/false whether the daemon is at a point it will start returning status
// or null if the AJAX connection to the daemon fails. lbry.call('status', {}, () => callback(true), null, () => callback(false))
lbry.call('is_running', {}, callback, null, function () {
callback(null);
});
}; };
lbry.getDaemonStatus = function (callback) { lbry.getDaemonStatus = function (callback) {