1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
import * as React from 'react';
import styled from 'styled-components';
import { TunnelState } from '../../shared/daemon-rpc-types';
import { messages } from '../../shared/gettext';
import ConnectionPanelContainer from '../containers/ConnectionPanelContainer';
import * as AppButton from './AppButton';
import { bigText } from './common-styles';
import ImageView from './ImageView';
import Marquee from './Marquee';
import { MultiButton } from './MultiButton';
import SecuredLabel, { SecuredDisplayStyle } from './SecuredLabel';
interface ITunnelControlProps {
tunnelState: TunnelState;
blockWhenDisconnected: boolean;
selectedRelayName: string;
city?: string;
country?: string;
onConnect: () => void;
onDisconnect: () => void;
onReconnect: () => void;
onSelectLocation: () => void;
}
const SwitchLocationButton = styled(AppButton.TransparentButton)({
marginBottom: '18px',
});
const Secured = styled(SecuredLabel)({
fontFamily: 'Open Sans',
fontSize: '16px',
fontWeight: 800,
lineHeight: '22px',
marginBottom: '2px',
});
const Footer = styled.div({
display: 'flex',
flexDirection: 'column',
flex: 0,
paddingBottom: '22px',
paddingLeft: '22px',
paddingRight: '22px',
});
const Body = styled.div({
display: 'flex',
flexDirection: 'column',
padding: '0 22px',
marginTop: '176px',
flex: 1,
});
const Wrapper = styled.div({
display: 'flex',
flexDirection: 'column',
flex: 1,
});
const Location = styled.div({
display: 'flex',
flexDirection: 'column',
marginBottom: 2,
});
const StyledMarquee = styled(Marquee)({
...bigText,
overflow: 'hidden',
});
const SelectedLocationChevron = styled(AppButton.Icon)({
margin: '0 4px',
});
export default class TunnelControl extends React.Component<ITunnelControlProps> {
public render() {
const SwitchLocation = () => {
return (
<SwitchLocationButton onClick={this.props.onSelectLocation}>
{messages.pgettext('tunnel-control', 'Switch location')}
</SwitchLocationButton>
);
};
const SelectedLocation = () => (
<SwitchLocationButton onClick={this.props.onSelectLocation}>
<AppButton.Label>{this.props.selectedRelayName}</AppButton.Label>
<SelectedLocationChevron height={12} width={7} source="icon-chevron" />
</SwitchLocationButton>
);
const Connect = () => (
<AppButton.GreenButton onClick={this.props.onConnect}>
{messages.pgettext('tunnel-control', 'Secure my connection')}
</AppButton.GreenButton>
);
const Disconnect = (props: React.ComponentProps<typeof AppButton.RedTransparentButton>) => (
<AppButton.RedTransparentButton onClick={this.props.onDisconnect} {...props}>
{messages.pgettext('tunnel-control', 'Disconnect')}
</AppButton.RedTransparentButton>
);
const Cancel = (props: React.ComponentProps<typeof AppButton.RedTransparentButton>) => (
<AppButton.RedTransparentButton onClick={this.props.onDisconnect} {...props}>
{messages.pgettext('tunnel-control', 'Cancel')}
</AppButton.RedTransparentButton>
);
const Dismiss = (props: React.ComponentProps<typeof AppButton.RedTransparentButton>) => (
<AppButton.RedTransparentButton onClick={this.props.onDisconnect} {...props}>
{messages.pgettext('tunnel-control', 'Dismiss')}
</AppButton.RedTransparentButton>
);
const Reconnect = (props: React.ComponentProps<typeof AppButton.RedTransparentButton>) => (
<AppButton.RedTransparentButton onClick={this.props.onReconnect} {...props}>
<ImageView height={22} width={22} source="icon-reload" tintColor="white" />
</AppButton.RedTransparentButton>
);
let state = this.props.tunnelState.state;
switch (this.props.tunnelState.state) {
case 'disconnecting':
switch (this.props.tunnelState.details) {
case 'block':
state = 'error';
break;
case 'reconnect':
state = 'connecting';
break;
default:
state = 'disconnecting';
break;
}
break;
}
switch (state) {
case 'connecting':
return (
<Wrapper>
<Body>
<Secured displayStyle={SecuredDisplayStyle.securing} />
<Location>
{this.renderCity()}
{this.renderCountry()}
</Location>
<ConnectionPanelContainer />
</Body>
<Footer>
<SwitchLocation />
<MultiButton mainButton={Cancel} sideButton={Reconnect} />
</Footer>
</Wrapper>
);
case 'connected':
return (
<Wrapper>
<Body>
<Secured displayStyle={SecuredDisplayStyle.secured} />
<Location>
{this.renderCity()}
{this.renderCountry()}
</Location>
<ConnectionPanelContainer />
</Body>
<Footer>
<SwitchLocation />
<MultiButton mainButton={Disconnect} sideButton={Reconnect} />
</Footer>
</Wrapper>
);
case 'error':
if (
this.props.tunnelState.state === 'error' &&
!this.props.tunnelState.details.isBlocking
) {
return (
<Wrapper>
<Body>
<Secured displayStyle={SecuredDisplayStyle.failedToSecure} />
</Body>
<Footer>
<SwitchLocation />
<MultiButton mainButton={Dismiss} sideButton={Reconnect} />
</Footer>
</Wrapper>
);
} else {
return (
<Wrapper>
<Body>
<Secured displayStyle={SecuredDisplayStyle.blocked} />
</Body>
<Footer>
<SwitchLocation />
<MultiButton mainButton={Cancel} sideButton={Reconnect} />
</Footer>
</Wrapper>
);
}
case 'disconnecting':
return (
<Wrapper>
<Body>
<Secured displayStyle={SecuredDisplayStyle.secured} />
<Location>{this.renderCountry()}</Location>
</Body>
<Footer>
<SelectedLocation />
<Connect />
</Footer>
</Wrapper>
);
case 'disconnected': {
const displayStyle = this.props.blockWhenDisconnected
? SecuredDisplayStyle.blocked
: SecuredDisplayStyle.unsecured;
return (
<Wrapper>
<Body>
<Secured displayStyle={displayStyle} />
<Location>{this.renderCountry()}</Location>
</Body>
<Footer>
<SelectedLocation />
<Connect />
</Footer>
</Wrapper>
);
}
default:
throw new Error(`Unknown TunnelState: ${this.props.tunnelState}`);
}
}
private renderCity() {
return <StyledMarquee>{this.props.city}</StyledMarquee>;
}
private renderCountry() {
return <StyledMarquee>{this.props.country}</StyledMarquee>;
}
}
|