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; onClose: () => void; } interface IState { showKillSwitchInfo: boolean; } export default class Preferences extends React.Component { public state = { showKillSwitchInfo: false }; public render() { return ( { // TRANSLATORS: Back button in navigation bar messages.pgettext('navigation-bar', 'Settings') } { // TRANSLATORS: Title label in navigation bar messages.pgettext('preferences-nav', 'Preferences') } {messages.pgettext('preferences-view', 'Preferences')} {messages.pgettext('preferences-view', 'Kill switch')} {messages.pgettext('preferences-view', 'Launch app on start-up')} {messages.pgettext('preferences-view', 'Auto-connect')} {messages.pgettext( 'preferences-view', 'Automatically connect to a server when the app launches.', )} {messages.pgettext('preferences-view', 'Block ads')} {messages.pgettext('preferences-view', 'Block trackers')} {this.props.dns.state === 'custom' && } {this.props.dns.state !== 'custom' && } {messages.pgettext('preferences-view', 'Local network sharing')} {messages.pgettext( 'preferences-view', 'Allows access to other devices on the same network for sharing, printing etc.', )} {messages.pgettext('preferences-view', 'Notifications')} {messages.pgettext( 'preferences-view', 'Enable or disable system notifications. The critical notifications will always be displayed.', )} {messages.pgettext('preferences-view', 'Monochromatic tray icon')} {messages.pgettext( 'preferences-view', 'Use a monochromatic tray icon instead of a colored one.', )} {(window.env.platform === 'win32' || (window.env.platform === 'darwin' && window.env.development)) && ( {messages.pgettext('preferences-view', 'Unpin app from taskbar')} {messages.pgettext( 'preferences-view', 'Enable to move the app around as a free-standing window.', )} )} {this.props.unpinnedWindow && ( {messages.pgettext('preferences-view', 'Start minimized')} {messages.pgettext( 'preferences-view', 'Show only the tray icon when the app starts.', )} )} {messages.pgettext('preferences-view', 'Beta program')} {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.', )} {this.state.showKillSwitchInfo && ( {messages.gettext('Got it!')} , ]} close={this.hideKillSwitchInfo} /> )} ); } 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 ( {formatMarkdown(sprintf(blockingDisabledText, { customDnsFeatureName }))} ); }