/* eslint-disable react/jsx-no-useless-fragment */ import { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import { autorun } from 'mobx'; import { observer, inject } from 'mobx-react'; import classnames from 'classnames'; import ServiceModel from '../../../models/Service'; import StatusBarTargetUrl from '../../ui/StatusBarTargetUrl'; import WebviewLoader from '../../ui/WebviewLoader'; import WebviewCrashHandler from './WebviewCrashHandler'; import WebviewErrorHandler from './ErrorHandlers/WebviewErrorHandler'; import ServiceDisabled from './ServiceDisabled'; import ServiceWebview from './ServiceWebview'; import SettingsStore from '../../../stores/SettingsStore'; import WebControlsScreen from '../../../features/webControls/containers/WebControlsScreen'; import { CUSTOM_WEBSITE_RECIPE_ID } from '../../../config'; class ServiceView extends Component { static propTypes = { service: PropTypes.instanceOf(ServiceModel).isRequired, setWebviewReference: PropTypes.func.isRequired, detachService: PropTypes.func.isRequired, reload: PropTypes.func.isRequired, edit: PropTypes.func.isRequired, enable: PropTypes.func.isRequired, isActive: PropTypes.bool, stores: PropTypes.shape({ settings: PropTypes.instanceOf(SettingsStore).isRequired, }).isRequired, isSpellcheckerEnabled: PropTypes.bool.isRequired, }; static defaultProps = { isActive: false, }; state = { forceRepaint: false, targetUrl: '', statusBarVisible: false, }; hibernationTimer = null; autorunDisposer = null; forceRepaintTimeout = null; componentDidMount() { this.autorunDisposer = autorun(() => { if (this.props.service.isActive) { this.setState({ forceRepaint: true }); this.forceRepaintTimeout = setTimeout(() => { this.setState({ forceRepaint: false }); }, 100); } }); } componentWillUnmount() { this.autorunDisposer(); clearTimeout(this.forceRepaintTimeout); clearTimeout(this.hibernationTimer); } render() { const { detachService, service, setWebviewReference, reload, edit, enable, stores, isSpellcheckerEnabled, } = this.props; const { navigationBarBehaviour } = stores.settings.app; const showNavBar = navigationBarBehaviour === 'always' || (navigationBarBehaviour === 'custom' && service.recipe.id === CUSTOM_WEBSITE_RECIPE_ID); const webviewClasses = classnames({ services__webview: true, 'services__webview-wrapper': true, 'is-active': service.isActive, 'services__webview--force-repaint': this.state.forceRepaint, }); let statusBar = null; if (this.state.statusBarVisible) { statusBar = ; } return (
{service.isActive && service.isEnabled && ( <> {service.hasCrashed && ( )} {service.isEnabled && service.isLoading && service.isFirstLoad && !service.isHibernating && !service.isServiceAccessRestricted && ( )} {service.isLoadingPage && !service.isFirstLoad && ( )} {service.isError && ( )} )} {!service.isEnabled ? ( <> {service.isActive && ( )} ) : ( <> {!service.isHibernating ? ( <> {showNavBar && } ) : (
😴

This service is currently hibernating.
Try switching services or reloading Ferdium.
)} )} {statusBar}
); } } export default inject('stores', 'actions')(observer(ServiceView));