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

149 lines
4.5 KiB
React
Raw Normal View History

2018-08-13 18:23:01 +02:00
// @flow
2018-03-26 23:32:43 +02:00
import * as React from 'react';
import { Lbry, MODALS } from 'lbry-redux';
2018-07-18 21:48:30 +02:00
import ModalWalletUnlock from 'modal/modalWalletUnlock';
import ModalIncompatibleDaemon from 'modal/modalIncompatibleDaemon';
import ModalUpgrade from 'modal/modalUpgrade';
import ModalDownloading from 'modal/modalDownloading';
2018-08-13 18:23:01 +02:00
import LoadScreen from './internal/load-screen';
2016-11-22 21:19:08 +01:00
2018-03-26 23:32:43 +02:00
type Props = {
checkDaemonVersion: () => Promise<any>,
2018-07-18 21:48:30 +02:00
notifyUnlockWallet: () => Promise<any>,
2018-08-13 18:23:01 +02:00
daemonVersionMatched: boolean,
onReadyToLaunch: () => void,
2018-08-16 07:17:15 +02:00
authenticate: () => void,
2018-04-23 20:02:06 +02:00
notification: ?{
id: string,
},
2018-03-26 23:32:43 +02:00
};
2017-05-17 10:10:25 +02:00
2018-03-26 23:32:43 +02:00
type State = {
details: string,
message: string,
isRunning: boolean,
2018-07-18 21:48:30 +02:00
launchedModal: boolean,
2018-03-26 23:32:43 +02:00
};
export class SplashScreen extends React.PureComponent<Props, State> {
constructor(props: Props) {
2017-05-17 10:10:25 +02:00
super(props);
this.state = {
2018-08-13 18:37:02 +02:00
details: __('Starting up'),
message: __('Connecting'),
isRunning: false,
2018-07-18 21:48:30 +02:00
launchedModal: false,
2017-05-17 10:10:25 +02:00
};
}
2018-08-13 18:23:01 +02:00
componentDidMount() {
const { checkDaemonVersion } = this.props;
Lbry.connect()
.then(checkDaemonVersion)
.then(() => {
this.updateStatus();
})
.catch(() => {
this.setState({
message: __('Connection Failure'),
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-05-17 10:10:25 +02:00
updateStatus() {
2018-04-18 06:03:01 +02:00
Lbry.status().then(status => {
2018-08-13 18:23:01 +02:00
this.updateStatusCallback(status);
2017-06-06 23:19:12 +02:00
});
2017-05-17 10:10:25 +02:00
}
2018-08-13 18:23:01 +02:00
updateStatusCallback(status) {
2018-08-16 07:17:15 +02:00
const { notifyUnlockWallet, authenticate } = this.props;
2018-07-18 21:48:30 +02:00
const { launchedModal } = this.state;
2018-08-16 07:17:15 +02:00
if (status) {
authenticate();
}
if (status.wallet && status.wallet.is_locked) {
2018-08-13 18:23:01 +02:00
this.setState({
isRunning: true,
});
2018-08-15 17:51:12 +02:00
2018-08-13 18:23:01 +02:00
if (launchedModal === false) {
this.setState({ launchedModal: true }, () => notifyUnlockWallet());
}
} else if (status.is_running) {
// 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({
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;
} else if (status.blockchain_headers && status.blockchain_headers.download_progress < 100) {
2017-07-29 23:52:32 +02:00
this.setState({
message: __('Blockchain Sync'),
2018-08-13 18:23:01 +02:00
details: `${__('Catching up with the blockchain')} (${
status.blockchain_headers.download_progress
}%)`,
2017-07-29 23:52:32 +02:00
});
2018-08-13 18:23:01 +02:00
} else if (status.wallet && status.wallet.blocks_behind > 0) {
const format = status.wallet.blocks_behind === 1 ? '%s block behind' : '%s blocks behind';
2018-07-18 21:48:30 +02:00
this.setState({
2018-08-13 18:23:01 +02:00
message: __('Blockchain Sync'),
details: __(format, status.wallet.blocks_behind),
2018-07-18 21:48:30 +02:00
});
} else if (status.wallet && status.wallet.blocks_behind === 0) {
2017-07-29 23:52:32 +02:00
this.setState({
2018-08-13 18:23:01 +02:00
message: 'Network Loading',
details: 'Initializing LBRY service...',
2017-07-29 23:52:32 +02:00
});
}
setTimeout(() => {
2017-04-09 17:06:23 +02:00
this.updateStatus();
}, 500);
2017-05-17 10:10:25 +02:00
}
render() {
2018-04-23 20:02:06 +02:00
const { notification } = this.props;
2018-08-13 18:23:01 +02:00
const { message, details, isRunning } = this.state;
2018-04-23 20:02:06 +02:00
const notificationId = notification && notification.id;
2018-08-13 18:23:01 +02:00
// {notificationId === MODALS.WALLET_UNLOCK && <ModalWalletUnlock />}
2017-06-06 23:19:12 +02:00
return (
2018-03-26 23:32:43 +02:00
<React.Fragment>
2018-08-13 18:23:01 +02:00
<LoadScreen message={message} details={details} />
{/* 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>
2018-07-18 21:48:30 +02:00
{notificationId === MODALS.WALLET_UNLOCK && <ModalWalletUnlock />}
{notificationId === MODALS.INCOMPATIBLE_DAEMON && <ModalIncompatibleDaemon />}
{notificationId === MODALS.UPGRADE && <ModalUpgrade />}
{notificationId === MODALS.DOWNLOADING && <ModalDownloading />}
2018-03-26 23:32:43 +02:00
</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;