summaryrefslogtreecommitdiffhomepage
path: root/gui/src/renderer/components/Preferences.tsx
blob: 4f66b60d4ab0021ee647630b7dc02428821845d7 (plain)
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
import * as React from 'react';
import { sprintf } from 'sprintf-js';
import { colors } from '../../config.json';
import { IDnsOptions } from '../../shared/daemon-rpc-types';
import { messages } from '../../shared/gettext';
import { formatMarkdown } from '../markdown-formatter';
import * as AppButton from './AppButton';
import { AriaDescription, AriaInput, AriaInputGroup, AriaLabel } from './AriaGroup';
import * as Cell from './cell';
import ImageView from './ImageView';
import { Layout } from './Layout';
import { ModalAlert, ModalAlertType, ModalContainer } from './Modal';
import {
  BackBarItem,
  NavigationBar,
  NavigationContainer,
  NavigationItems,
  NavigationScrollbars,
  TitleBarItem,
} from './NavigationBar';
import { StyledContainer, StyledContent, StyledSeparator } from './PreferencesStyles';
import SettingsHeader, { HeaderTitle } from './SettingsHeader';

export interface IProps {
  autoStart: boolean;
  autoConnect: boolean;
  allowLan: boolean;
  showBetaReleases: boolean;
  isBeta: boolean;
  enableSystemNotifications: boolean;
  monochromaticIcon: boolean;
  startMinimized: boolean;
  unpinnedWindow: boolean;
  dns: IDnsOptions;
  setAutoStart: (autoStart: boolean) => void;
  setEnableSystemNotifications: (flag: boolean) => void;
  setAutoConnect: (autoConnect: boolean) => void;
  setAllowLan: (allowLan: boolean) => void;
  setShowBetaReleases: (showBetaReleases: boolean) => void;
  setStartMinimized: (startMinimized: boolean) => void;
  setMonochromaticIcon: (monochromaticIcon: boolean) => void;
  setUnpinnedWindow: (unpinnedWindow: boolean) => void;
  setDnsOptions: (dns: IDnsOptions) => Promise<void>;
  onClose: () => void;
}

interface IState {
  showKillSwitchInfo: boolean;
}

export default class Preferences extends React.Component<IProps, IState> {
  public state = { showKillSwitchInfo: false };

  public render() {
    return (
      <ModalContainer>
        <Layout>
          <StyledContainer>
            <NavigationContainer>
              <NavigationBar>
                <NavigationItems>
                  <BackBarItem action={this.props.onClose}>
                    {
                      // TRANSLATORS: Back button in navigation bar
                      messages.pgettext('navigation-bar', 'Settings')
                    }
                  </BackBarItem>
                  <TitleBarItem>
                    {
                      // TRANSLATORS: Title label in navigation bar
                      messages.pgettext('preferences-nav', 'Preferences')
                    }
                  </TitleBarItem>
                </NavigationItems>
              </NavigationBar>

              <NavigationScrollbars>
                <SettingsHeader>
                  <HeaderTitle>{messages.pgettext('preferences-view', 'Preferences')}</HeaderTitle>
                </SettingsHeader>

                <StyledContent>
                  <Cell.CellButton onClick={this.showKillSwitchInfo}>
                    <Cell.InputLabel>
                      {messages.pgettext('preferences-view', 'Kill switch')}
                    </Cell.InputLabel>
                    <ImageView source="icon-info" width={24} tintColor={colors.white} />
                  </Cell.CellButton>
                  <StyledSeparator height={20} />

                  <AriaInputGroup>
                    <Cell.Container>
                      <AriaLabel>
                        <Cell.InputLabel>
                          {messages.pgettext('preferences-view', 'Launch app on start-up')}
                        </Cell.InputLabel>
                      </AriaLabel>
                      <AriaInput>
                        <Cell.Switch
                          isOn={this.props.autoStart}
                          onChange={this.props.setAutoStart}
                        />
                      </AriaInput>
                    </Cell.Container>
                  </AriaInputGroup>
                  <StyledSeparator />

                  <AriaInputGroup>
                    <Cell.Container>
                      <AriaLabel>
                        <Cell.InputLabel>
                          {messages.pgettext('preferences-view', 'Auto-connect')}
                        </Cell.InputLabel>
                      </AriaLabel>
                      <AriaInput>
                        <Cell.Switch
                          isOn={this.props.autoConnect}
                          onChange={this.props.setAutoConnect}
                        />
                      </AriaInput>
                    </Cell.Container>
                    <Cell.Footer>
                      <AriaDescription>
                        <Cell.FooterText>
                          {messages.pgettext(
                            'preferences-view',
                            'Automatically connect to a server when the app launches.',
                          )}
                        </Cell.FooterText>
                      </AriaDescription>
                    </Cell.Footer>
                  </AriaInputGroup>

                  <AriaInputGroup>
                    <Cell.Container disabled={this.props.dns.state === 'custom'}>
                      <AriaLabel>
                        <Cell.InputLabel>
                          {messages.pgettext('preferences-view', 'Block ads')}
                        </Cell.InputLabel>
                      </AriaLabel>
                      <AriaInput>
                        <Cell.Switch
                          isOn={
                            this.props.dns.state === 'default' &&
                            this.props.dns.defaultOptions.blockAds
                          }
                          onChange={this.setBlockAds}
                        />
                      </AriaInput>
                    </Cell.Container>
                  </AriaInputGroup>
                  <StyledSeparator />
                  <AriaInputGroup>
                    <Cell.Container disabled={this.props.dns.state === 'custom'}>
                      <AriaLabel>
                        <Cell.InputLabel>
                          {messages.pgettext('preferences-view', 'Block trackers')}
                        </Cell.InputLabel>
                      </AriaLabel>
                      <AriaInput>
                        <Cell.Switch
                          isOn={
                            this.props.dns.state === 'default' &&
                            this.props.dns.defaultOptions.blockTrackers
                          }
                          onChange={this.setBlockTrackers}
                        />
                      </AriaInput>
                    </Cell.Container>
                    {this.props.dns.state === 'custom' && <CustomDnsEnabledFooter />}
                  </AriaInputGroup>

                  {this.props.dns.state !== 'custom' && <StyledSeparator height={20} />}

                  <AriaInputGroup>
                    <Cell.Container>
                      <AriaLabel>
                        <Cell.InputLabel>
                          {messages.pgettext('preferences-view', 'Local network sharing')}
                        </Cell.InputLabel>
                      </AriaLabel>
                      <AriaInput>
                        <Cell.Switch isOn={this.props.allowLan} onChange={this.props.setAllowLan} />
                      </AriaInput>
                    </Cell.Container>
                    <Cell.Footer>
                      <AriaDescription>
                        <Cell.FooterText>
                          {messages.pgettext(
                            'preferences-view',
                            'Allows access to other devices on the same network for sharing, printing etc.',
                          )}
                        </Cell.FooterText>
                      </AriaDescription>
                    </Cell.Footer>
                  </AriaInputGroup>

                  <AriaInputGroup>
                    <Cell.Container>
                      <AriaLabel>
                        <Cell.InputLabel>
                          {messages.pgettext('preferences-view', 'Notifications')}
                        </Cell.InputLabel>
                      </AriaLabel>
                      <AriaInput>
                        <Cell.Switch
                          isOn={this.props.enableSystemNotifications}
                          onChange={this.props.setEnableSystemNotifications}
                        />
                      </AriaInput>
                    </Cell.Container>
                    <Cell.Footer>
                      <AriaDescription>
                        <Cell.FooterText>
                          {messages.pgettext(
                            'preferences-view',
                            'Enable or disable system notifications. The critical notifications will always be displayed.',
                          )}
                        </Cell.FooterText>
                      </AriaDescription>
                    </Cell.Footer>
                  </AriaInputGroup>

                  <AriaInputGroup>
                    <Cell.Container>
                      <AriaLabel>
                        <Cell.InputLabel>
                          {messages.pgettext('preferences-view', 'Monochromatic tray icon')}
                        </Cell.InputLabel>
                      </AriaLabel>
                      <AriaInput>
                        <Cell.Switch
                          isOn={this.props.monochromaticIcon}
                          onChange={this.props.setMonochromaticIcon}
                        />
                      </AriaInput>
                    </Cell.Container>
                    <Cell.Footer>
                      <AriaDescription>
                        <Cell.FooterText>
                          {messages.pgettext(
                            'preferences-view',
                            'Use a monochromatic tray icon instead of a colored one.',
                          )}
                        </Cell.FooterText>
                      </AriaDescription>
                    </Cell.Footer>
                  </AriaInputGroup>

                  {(window.env.platform === 'win32' ||
                    (window.env.platform === 'darwin' && window.env.development)) && (
                    <AriaInputGroup>
                      <Cell.Container>
                        <AriaLabel>
                          <Cell.InputLabel>
                            {messages.pgettext('preferences-view', 'Unpin app from taskbar')}
                          </Cell.InputLabel>
                        </AriaLabel>
                        <AriaInput>
                          <Cell.Switch
                            isOn={this.props.unpinnedWindow}
                            onChange={this.props.setUnpinnedWindow}
                          />
                        </AriaInput>
                      </Cell.Container>
                      <Cell.Footer>
                        <AriaDescription>
                          <Cell.FooterText>
                            {messages.pgettext(
                              'preferences-view',
                              'Enable to move the app around as a free-standing window.',
                            )}
                          </Cell.FooterText>
                        </AriaDescription>
                      </Cell.Footer>
                    </AriaInputGroup>
                  )}

                  {this.props.unpinnedWindow && (
                    <React.Fragment>
                      <AriaInputGroup>
                        <Cell.Container>
                          <AriaLabel>
                            <Cell.InputLabel>
                              {messages.pgettext('preferences-view', 'Start minimized')}
                            </Cell.InputLabel>
                          </AriaLabel>
                          <AriaInput>
                            <Cell.Switch
                              isOn={this.props.startMinimized}
                              onChange={this.props.setStartMinimized}
                            />
                          </AriaInput>
                        </Cell.Container>
                        <Cell.Footer>
                          <AriaDescription>
                            <Cell.FooterText>
                              {messages.pgettext(
                                'preferences-view',
                                'Show only the tray icon when the app starts.',
                              )}
                            </Cell.FooterText>
                          </AriaDescription>
                        </Cell.Footer>
                      </AriaInputGroup>
                    </React.Fragment>
                  )}

                  <AriaInputGroup>
                    <Cell.Container disabled={this.props.isBeta}>
                      <AriaLabel>
                        <Cell.InputLabel>
                          {messages.pgettext('preferences-view', 'Beta program')}
                        </Cell.InputLabel>
                      </AriaLabel>
                      <AriaInput>
                        <Cell.Switch
                          isOn={this.props.showBetaReleases}
                          onChange={this.props.setShowBetaReleases}
                        />
                      </AriaInput>
                    </Cell.Container>
                    <Cell.Footer>
                      <AriaDescription>
                        <Cell.FooterText>
                          {this.props.isBeta
                            ? messages.pgettext(
                                'preferences-view',
                                'This option is unavailable while using a beta version.',
                              )
                            : messages.pgettext(
                                'preferences-view',
                                'Enable to get notified when new beta versions of the app are released.',
                              )}
                        </Cell.FooterText>
                      </AriaDescription>
                    </Cell.Footer>
                  </AriaInputGroup>
                </StyledContent>
              </NavigationScrollbars>
            </NavigationContainer>
          </StyledContainer>
        </Layout>

        {this.state.showKillSwitchInfo && (
          <ModalAlert
            message={messages.pgettext(
              'preferences-view',
              'The app has a built in kill switch that is enabled by default and cannot be disabled. This is to prevent your traffic from leaking outside of the VPN tunnel if your network suddenly stops working or if the tunnel fails for any reason. Mullvad automatically protects your data until your connection is reestablished.',
            )}
            type={ModalAlertType.info}
            buttons={[
              <AppButton.BlueButton key="back" onClick={this.hideKillSwitchInfo}>
                {messages.gettext('Got it!')}
              </AppButton.BlueButton>,
            ]}
            close={this.hideKillSwitchInfo}
          />
        )}
      </ModalContainer>
    );
  }

  private setBlockAds = async (enabled: boolean) => {
    await this.props.setDnsOptions({
      ...this.props.dns,
      defaultOptions: {
        ...this.props.dns.defaultOptions,
        blockAds: enabled,
      },
    });
  };

  private setBlockTrackers = async (enabled: boolean) => {
    await this.props.setDnsOptions({
      ...this.props.dns,
      defaultOptions: {
        ...this.props.dns.defaultOptions,
        blockTrackers: enabled,
      },
    });
  };

  private showKillSwitchInfo = () => {
    this.setState({ showKillSwitchInfo: true });
  };

  private hideKillSwitchInfo = () => {
    this.setState({ showKillSwitchInfo: false });
  };
}

function CustomDnsEnabledFooter() {
  const customDnsFeatureName = messages.pgettext('advanced-settings-view', 'Use custom DNS server');

  // TRANSLATORS: This is displayed when the custom DNS setting is turned on which makes the block
  // TRANSLATORS: ads/trackers settings disabled. The text enclosed in "**" will appear bold.
  // TRANSLATORS: Advanced settings refer to the name of the page with the title "Advanced".
  // TRANSLATORS: Available placeholders:
  // TRANSLATORS: %(customDnsFeatureName)s - The name displayed next to the custom DNS toggle.
  const blockingDisabledText = messages.pgettext(
    'preferences-view',
    'Disable **%(customDnsFeatureName)s** (under Advanced settings) to activate these settings.',
  );

  return (
    <Cell.Footer>
      <AriaDescription>
        <Cell.FooterText>
          {formatMarkdown(sprintf(blockingDisabledText, { customDnsFeatureName }))}
        </Cell.FooterText>
      </AriaDescription>
    </Cell.Footer>
  );
}