// @flow import * as ICONS from 'constants/icons'; import * as SETTINGS from 'constants/settings'; import * as React from 'react'; import { FormField, FormFieldPrice, FormRow } from 'component/common/form'; import Button from 'component/button'; import Page from 'component/page'; import FileSelector from 'component/common/file-selector'; export type Price = { currency: string, amount: number, }; type DaemonSettings = { download_directory: string, disable_max_key_fee: boolean, share_usage_data: boolean, max_key_fee?: Price, }; type Props = { setDaemonSetting: (string, boolean | string | Price) => void, setClientSetting: (string, boolean | string | number | Price) => void, clearCache: () => Promise, getThemes: () => void, daemonSettings: DaemonSettings, showNsfw: boolean, instantPurchaseEnabled: boolean, instantPurchaseMax: Price, currentTheme: string, themes: Array, automaticDarkModeEnabled: boolean, autoplay: boolean, autoDownload: boolean, encryptWallet: () => void, decryptWallet: () => void, updateWalletStatus: () => void, walletEncrypted: boolean, osNotificationsEnabled: boolean, }; type State = { clearingCache: boolean, }; class SettingsPage extends React.PureComponent { constructor(props: Props) { super(props); this.state = { clearingCache: false, }; (this: any).onDownloadDirChange = this.onDownloadDirChange.bind(this); (this: any).onKeyFeeChange = this.onKeyFeeChange.bind(this); (this: any).onInstantPurchaseMaxChange = this.onInstantPurchaseMaxChange.bind(this); (this: any).onShowNsfwChange = this.onShowNsfwChange.bind(this); (this: any).onShareDataChange = this.onShareDataChange.bind(this); (this: any).onThemeChange = this.onThemeChange.bind(this); (this: any).onAutomaticDarkModeChange = this.onAutomaticDarkModeChange.bind(this); (this: any).onAutoplayChange = this.onAutoplayChange.bind(this); (this: any).clearCache = this.clearCache.bind(this); (this: any).onDesktopNotificationsChange = this.onDesktopNotificationsChange.bind(this); (this: any).onAutoDownloadChange = this.onAutoDownloadChange.bind(this); // (this: any).onLanguageChange = this.onLanguageChange.bind(this) } componentDidMount() { this.props.getThemes(); this.props.updateWalletStatus(); } onRunOnStartChange(event: SyntheticInputEvent<*>) { this.setDaemonSetting('run_on_startup', event.target.checked); } onShareDataChange(event: SyntheticInputEvent<*>) { this.setDaemonSetting('share_usage_data', event.target.checked); } onDownloadDirChange(newDirectory: string) { this.setDaemonSetting('download_directory', newDirectory); } onKeyFeeChange(newValue: Price) { this.setDaemonSetting('max_key_fee', newValue); } onKeyFeeDisableChange(isDisabled: boolean) { this.setDaemonSetting('disable_max_key_fee', isDisabled); } onThemeChange(event: SyntheticInputEvent<*>) { const { value } = event.target; if (value === 'dark') { this.onAutomaticDarkModeChange(false); } this.props.setClientSetting(SETTINGS.THEME, value); } onAutomaticDarkModeChange(value: boolean) { this.props.setClientSetting(SETTINGS.AUTOMATIC_DARK_MODE_ENABLED, value); } onAutoplayChange(event: SyntheticInputEvent<*>) { this.props.setClientSetting(SETTINGS.AUTOPLAY, event.target.checked); } onInstantPurchaseEnabledChange(enabled: boolean) { this.props.setClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED, enabled); } onInstantPurchaseMaxChange(newValue: Price) { this.props.setClientSetting(SETTINGS.INSTANT_PURCHASE_MAX, newValue); } onShowNsfwChange(event: SyntheticInputEvent<*>) { this.props.setClientSetting(SETTINGS.SHOW_NSFW, event.target.checked); } onAutoDownloadChange(event: SyntheticInputEvent<*>) { this.props.setClientSetting(SETTINGS.AUTO_DOWNLOAD, event.target.checked); } onChangeEncryptWallet() { const { decryptWallet, walletEncrypted, encryptWallet } = this.props; if (walletEncrypted) { decryptWallet(); } else { encryptWallet(); } } onDesktopNotificationsChange(event: SyntheticInputEvent<*>) { this.props.setClientSetting(SETTINGS.OS_NOTIFICATIONS_ENABLED, event.target.checked); } setDaemonSetting(name: string, value: boolean | string | Price) { this.props.setDaemonSetting(name, value); } clearCache() { this.setState({ clearingCache: true, }); const success = () => { this.setState({ clearingCache: false }); window.location.href = 'index.html'; }; const clear = () => this.props.clearCache().then(success); setTimeout(clear, 1000, { once: true }); } render() { const { daemonSettings, showNsfw, instantPurchaseEnabled, instantPurchaseMax, currentTheme, themes, automaticDarkModeEnabled, autoplay, walletEncrypted, osNotificationsEnabled, autoDownload, } = this.props; const noDaemonSettings = !daemonSettings || Object.keys(daemonSettings).length === 0; const isDarkModeEnabled = currentTheme === 'dark'; return ( {noDaemonSettings ? (
{__('Failed to load settings.')}
) : (

{__('Download Directory')}

{__('LBRY downloads will be saved here.')}

{__('Max Purchase Price')}

{__( 'This will prevent you from purchasing any content over a certain cost, as a safety measure.' )}

{ this.onKeyFeeDisableChange(true); }} /> { this.onKeyFeeDisableChange(false); }} checked={!daemonSettings.disable_max_key_fee} postfix={__('Choose limit')} /> {!daemonSettings.disable_max_key_fee && ( )}

{__('Purchase Confirmations')}

{__( "When this option is chosen, LBRY won't ask you to confirm downloads below your chosen price." )}

{ this.onInstantPurchaseEnabledChange(false); }} /> { this.onInstantPurchaseEnabledChange(true); }} /> {instantPurchaseEnabled && ( )}

{__('Content Settings')}

{__('Notifications')}

{__('Share Diagnostic Data')}

{__('Theme')}

{themes.map(theme => ( ))} this.onAutomaticDarkModeChange(e.target.checked)} checked={automaticDarkModeEnabled} disabled={isDarkModeEnabled} postfix={__('Automatic dark mode (9pm to 8am)')} />

{__('Wallet Security')}

this.onChangeEncryptWallet()} checked={walletEncrypted} postfix={__('Encrypt my wallet with a custom password.')} helper={ {__('Secure your local wallet data with a custom password.')}{' '} {__('Lost passwords cannot be recovered.')}

{__('Experimental Settings')}

{__('Application Cache')}

{__('This will clear the application cache. Your wallet will not be affected.')}

)}
); } } export default SettingsPage;