lbry-desktop/src/renderer/component/splash/view.jsx

125 lines
3.7 KiB
React
Raw Normal View History

2018-03-26 23:32:43 +02:00
import * as React from 'react';
2018-04-18 06:03:01 +02:00
import { Lbry } from 'lbry-redux';
2018-03-26 23:32:43 +02:00
import LoadScreen from './internal/load-screen';
import ModalIncompatibleDaemon from 'modal/modalIncompatibleDaemon';
import ModalUpgrade from 'modal/modalUpgrade';
import ModalDownloading from 'modal/modalDownloading';
import * as modals from 'constants/modal_types';
2016-11-22 21:19:08 +01:00
2018-03-26 23:32:43 +02:00
type Props = {
checkDaemonVersion: () => Promise<any>,
modal: string,
};
2017-05-17 10:10:25 +02:00
2018-03-26 23:32:43 +02:00
type State = {
details: string,
message: string,
isRunning: boolean,
isLagging: boolean,
};
export class SplashScreen extends React.PureComponent<Props, State> {
constructor(props: Props) {
2017-05-17 10:10:25 +02:00
super(props);
this.state = {
details: __('Starting daemon'),
message: __('Connecting'),
isRunning: false,
isLagging: false,
2017-05-17 10:10:25 +02:00
};
}
updateStatus() {
2018-04-18 06:03:01 +02:00
Lbry.status().then(status => {
2017-06-06 23:19:12 +02:00
this._updateStatusCallback(status);
});
2017-05-17 10:10:25 +02:00
}
_updateStatusCallback(status) {
2017-06-06 23:19:12 +02:00
const startupStatus = status.startup_status;
if (startupStatus.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({
message: __('Testing Network'),
details: __('Waiting for name resolution'),
2017-06-06 23:19:12 +02:00
isLagging: false,
isRunning: true,
});
2018-04-18 06:03:01 +02:00
Lbry.resolve({ uri: 'lbry://one' }).then(() => {
// Only leave the load screen if the daemon version matched;
// otherwise we'll notify the user at the end of the load screen.
if (this.props.daemonVersionMatched) {
this.props.onReadyToLaunch();
}
});
return;
}
if (status.blockchain_status && status.blockchain_status.blocks_behind > 0) {
2017-11-24 15:31:05 +01:00
const format =
status.blockchain_status.blocks_behind == 1 ? '%s block behind' : '%s blocks behind';
2017-07-29 23:52:32 +02:00
this.setState({
message: __('Blockchain Sync'),
details: __(format, status.blockchain_status.blocks_behind),
2017-07-29 23:52:32 +02:00
isLagging: startupStatus.is_lagging,
});
} else {
this.setState({
message: __('Network Loading'),
details: startupStatus.message + (startupStatus.is_lagging ? '' : '...'),
2017-07-29 23:52:32 +02:00
isLagging: startupStatus.is_lagging,
});
}
setTimeout(() => {
2017-04-09 17:06:23 +02:00
this.updateStatus();
}, 500);
2017-05-17 10:10:25 +02:00
}
componentDidMount() {
2018-03-26 23:32:43 +02:00
const { checkDaemonVersion } = this.props;
2018-04-18 06:03:01 +02:00
Lbry.connect()
2018-03-26 23:32:43 +02:00
.then(checkDaemonVersion)
2017-06-06 23:19:12 +02:00
.then(() => {
this.updateStatus();
})
2017-05-31 01:56:48 +02:00
.catch(() => {
2017-04-09 17:06:23 +02:00
this.setState({
isLagging: true,
message: __('Connection Failure'),
2017-06-06 23:19:12 +02:00
details: __(
'Try closing all LBRY processes and starting again. If this still happens, your anti-virus software or firewall may be preventing LBRY from connecting. Contact hello@lbry.io if you think this is a software bug.'
2017-06-06 23:19:12 +02:00
),
});
});
2017-05-17 10:10:25 +02:00
}
render() {
const { modal } = this.props;
2017-12-10 21:27:55 +01:00
const { message, details, isLagging, isRunning } = this.state;
2017-06-06 23:19:12 +02:00
return (
2018-03-26 23:32:43 +02:00
<React.Fragment>
<LoadScreen message={message} details={details} isWarning={isLagging} />
{/* Temp hack: don't show any modals on splash screen daemon is running;
daemon doesn't let you quit during startup, so the "Quit" buttons
in the modals won't work. */}
2018-03-26 23:32:43 +02:00
{isRunning && (
<React.Fragment>
{modal === modals.INCOMPATIBLE_DAEMON && <ModalIncompatibleDaemon />}
{modal === modals.UPGRADE && <ModalUpgrade />}
{modal === modals.DOWNLOADING && <ModalDownloading />}
</React.Fragment>
)}
</React.Fragment>
2017-06-06 23:19:12 +02:00
);
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;