2016-11-22 21:19:08 +01:00
|
|
|
import React from 'react';
|
|
|
|
import lbry from '../lbry.js';
|
|
|
|
import LoadScreen from './load_screen.js';
|
|
|
|
|
2017-05-17 10:10:25 +02:00
|
|
|
export class SplashScreen extends React.Component {
|
|
|
|
static propTypes = {
|
2016-04-10 02:00:56 +02:00
|
|
|
message: React.PropTypes.string,
|
2016-04-14 07:49:00 +02:00
|
|
|
onLoadDone: React.PropTypes.func,
|
2017-05-17 10:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
2017-05-26 02:16:25 +02:00
|
|
|
details: __('Starting daemon'),
|
2016-04-15 12:41:01 +02:00
|
|
|
isLagging: false,
|
2017-05-17 10:10:25 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
updateStatus() {
|
2017-05-18 03:37:39 +02:00
|
|
|
lbry.status().then((status) => { this._updateStatusCallback(status) });
|
2017-05-17 10:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
_updateStatusCallback(status) {
|
2017-04-09 17:06:23 +02:00
|
|
|
const startupStatus = status.startup_status
|
|
|
|
if (startupStatus.code == 'started') {
|
2017-01-18 16:29:47 +01:00
|
|
|
// 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({
|
2017-05-26 02:16:25 +02:00
|
|
|
details: __('Waiting for name resolution'),
|
2017-01-18 16:29:47 +01:00
|
|
|
isLagging: false
|
|
|
|
});
|
2016-04-14 08:27:06 +02:00
|
|
|
|
2017-04-11 06:14:52 +02:00
|
|
|
lbry.resolve({uri: 'lbry://one'}).then(() => {
|
2017-01-18 16:29:47 +01:00
|
|
|
this.props.onLoadDone();
|
2016-04-14 08:27:06 +02:00
|
|
|
});
|
2017-01-18 16:29:47 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setState({
|
2017-04-09 17:06:23 +02:00
|
|
|
details: startupStatus.message + (startupStatus.is_lagging ? '' : '...'),
|
|
|
|
isLagging: startupStatus.is_lagging,
|
2017-01-18 16:29:47 +01:00
|
|
|
});
|
|
|
|
setTimeout(() => {
|
2017-04-09 17:06:23 +02:00
|
|
|
this.updateStatus();
|
2017-01-18 16:29:47 +01:00
|
|
|
}, 500);
|
2017-05-17 10:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2017-04-09 17:06:23 +02:00
|
|
|
lbry.connect().then((isConnected) => {
|
|
|
|
if (isConnected) {
|
|
|
|
this.updateStatus();
|
|
|
|
} else {
|
|
|
|
this.setState({
|
|
|
|
isLagging: true,
|
2017-05-26 02:16:25 +02:00
|
|
|
message: __("Failed to connect to LBRY"),
|
|
|
|
details: __("LBRY was unable to start and connect properly.")
|
2017-04-09 17:06:23 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
2017-05-17 10:10:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-04-09 17:06:23 +02:00
|
|
|
return <LoadScreen message={this.props.message} details={this.state.details} isWarning={this.state.isLagging} />
|
2016-04-10 02:00:56 +02:00
|
|
|
}
|
2017-05-17 10:10:25 +02:00
|
|
|
}
|
2016-11-22 21:19:08 +01:00
|
|
|
|
|
|
|
export default SplashScreen;
|