import * as React from 'react'; import { Component, Styles, Text, Types, View } from 'reactxp'; import { colors } from '../../config.json'; import { messages } from '../../shared/gettext'; import * as AppButton from './AppButton'; import ConnectionInfo from './ConnectionInfo'; import SecuredLabel, { SecuredDisplayStyle } from './SecuredLabel'; import { RelayProtocol, TunnelStateTransition } from '../../shared/daemon-rpc-types'; export interface IRelayInAddress { ip: string; port: number; protocol: RelayProtocol; } export interface IRelayOutAddress { ipv4?: string; ipv6?: string; } interface ITunnelControlProps { tunnelState: TunnelStateTransition; selectedRelayName: string; city?: string; country?: string; hostname?: string; defaultConnectionInfoOpen?: boolean; relayInAddress?: IRelayInAddress; relayOutAddress?: IRelayOutAddress; onConnect: () => void; onDisconnect: () => void; onSelectLocation: () => void; onToggleConnectionInfo: (value: boolean) => void; } const styles = { body: Styles.createViewStyle({ paddingTop: 0, paddingLeft: 24, paddingRight: 24, paddingBottom: 0, marginTop: 186, flex: 1, }), footer: Styles.createViewStyle({ flex: 0, paddingBottom: 16, paddingLeft: 24, paddingRight: 24, }), wrapper: Styles.createViewStyle({ flex: 1, }), switch_location_button: Styles.createViewStyle({ marginBottom: 16, }), status_security: Styles.createTextStyle({ fontFamily: 'Open Sans', fontSize: 16, fontWeight: '800', lineHeight: 22, marginBottom: 4, }), status_location: Styles.createTextStyle({ flexDirection: 'column', marginBottom: 4, }), status_location_text: Styles.createTextStyle({ fontFamily: 'DINPro', fontSize: 34, lineHeight: 36, fontWeight: '900', overflow: 'hidden', letterSpacing: -0.9, color: colors.white, }), }; export default class TunnelControl extends Component { public render() { const Location = ({ children }: { children?: React.ReactNode }) => ( {children} ); const City = () => {this.props.city}; const Country = () => {this.props.country}; const SwitchLocation = () => { return ( {messages.pgettext('tunnel-control', 'Switch location')} ); }; const SelectedLocation = () => ( {this.props.selectedRelayName} ); const Connect = () => ( {messages.pgettext('tunnel-control', 'Secure my connection')} ); const Disconnect = () => ( {messages.pgettext('tunnel-control', 'Disconnect')} ); const Cancel = () => ( {messages.pgettext('tunnel-control', 'Cancel')} ); const Secured = ({ displayStyle }: { displayStyle: SecuredDisplayStyle }) => ( ); const Footer = ({ children }: { children: React.ReactNode }) => ( {children} ); const connectionDetails = ( ); let state = this.props.tunnelState.state; switch (this.props.tunnelState.state) { case 'blocked': switch (this.props.tunnelState.details.reason) { case 'set_firewall_policy_error': state = 'disconnected'; break; default: state = 'blocked'; break; } break; case 'disconnecting': switch (this.props.tunnelState.details) { case 'block': state = 'blocked'; break; case 'reconnect': state = 'connecting'; break; default: state = 'disconnecting'; break; } break; } switch (state) { case 'connecting': return ( {connectionDetails}
); case 'connected': return ( {connectionDetails}
); case 'blocked': return (
); case 'disconnecting': return (
); case 'disconnected': return (
); default: throw new Error(`Unknown TunnelState: ${this.props.tunnelState}`); } } } interface IContainerProps { children?: Types.ReactNode; } class Wrapper extends Component { public render() { return {this.props.children}; } } class Body extends Component { public render() { return {this.props.children}; } }