From 2aa10261d957a73144b86c2ecc70b71b8f7869e7 Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Wed, 18 Jan 2017 09:29:47 -0600 Subject: [PATCH] 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. --- js/component/splash.js | 42 +++++++++++++++++++++++++++--------------- js/lbry.js | 23 ++++++++++------------- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/js/component/splash.js b/js/component/splash.js index bcb045468..29cb65234 100644 --- a/js/component/splash.js +++ b/js/component/splash.js @@ -14,24 +14,36 @@ var SplashScreen = React.createClass({ } }, updateStatus: function(was_lagging=false) { - lbry.getDaemonStatus((status) => { - if (status.code == 'started') { - this.props.onLoadDone(); - return; - } - - this.setState({ - details: status.message + (status.is_lagging ? '' : '...'), - isLagging: status.is_lagging, - }); - - setTimeout(() => { - this.updateStatus(status.is_lagging); - }, 500); + lbry.getDaemonStatus(this._updateStatusCallback); + }, + _updateStatusCallback: function(status) { + if (status.code == 'started') { + // Wait until we are able to resolve a name before declaring + // that we are done. + // TODO: This is a hack, and the logic should live in the daemon + // to give us a better sense of when we are actually started + this.setState({ + details: 'Waiting for name resolution', + isLagging: false }); + + 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() { - this.updateStatus(); + lbry.connect((connected) => { + this.updateStatus(); + }); }, render: function() { return ; diff --git a/js/lbry.js b/js/lbry.js index 65fb4e821..9063aca2e 100644 --- a/js/lbry.js +++ b/js/lbry.js @@ -90,17 +90,18 @@ lbry.call = function (method, params, callback, errorCallback, connectFailedCall //core lbry.connect = function(callback) { - // Check every half second to see if the daemon's running. - // Returns true to callback once connected, or false if it takes too long and we give up. - function checkDaemonRunning(tryNum=0) { - lbry.daemonRunningStatus(function (runningStatus) { + // Check every half second to see if the daemon is accepting connections + // Once this returns True, can call getDaemonStatus to see where + // we are in the startup process + function checkDaemonStarted(tryNum=0) { + lbry.isDaemonAcceptingConnections(function (runningStatus) { if (runningStatus) { lbry.isConnected = true; callback(true); } else { if (tryNum <= 600) { // Move # of tries into constant or config option setTimeout(function () { - checkDaemonRunning(tryNum + 1); + checkDaemonStarted(tryNum + 1); }, 500); } else { callback(false); @@ -108,16 +109,12 @@ lbry.connect = function(callback) } }); } - checkDaemonRunning(); + checkDaemonStarted(); } -lbry.daemonRunningStatus = function (callback) { - // Returns true/false whether the daemon is running (i.e. fully conncected to the network), - // or null if the AJAX connection to the daemon fails. - - lbry.call('is_running', {}, callback, null, function () { - callback(null); - }); +lbry.isDaemonAcceptingConnections = function (callback) { + // Returns true/false whether the daemon is at a point it will start returning status + lbry.call('status', {}, () => callback(true), null, () => callback(false)) }; lbry.getDaemonStatus = function (callback) {