// @flow import * as React from 'react'; import { FormField, FormFieldPrice } from 'component/common/form'; import Button from 'component/button'; import I18nMessage from 'component/i18nMessage'; import Page from 'component/page'; import SettingWalletServer from 'component/settingWalletServer'; import SettingAutoLaunch from 'component/settingAutoLaunch'; import FileSelector from 'component/common/file-selector'; import { SETTINGS } from 'lbry-redux'; import Card from 'component/common/card'; import { getPasswordFromCookie } from 'util/saved-passwords'; import Spinner from 'component/spinner'; // @if TARGET='app' const IS_MAC = process.platform === 'darwin'; // @endif type Price = { currency: string, amount: number, }; type SetDaemonSettingArg = boolean | string | number | Price; type DaemonSettings = { download_dir: string, share_usage_data: boolean, max_key_fee?: Price, max_connections_per_download?: number, save_files: boolean, save_blobs: boolean, ffmpeg_path: string, }; type Props = { setDaemonSetting: (string, ?SetDaemonSettingArg) => void, clearDaemonSetting: string => void, setClientSetting: (string, SetDaemonSettingArg) => void, daemonSettings: DaemonSettings, isAuthenticated: boolean, instantPurchaseEnabled: boolean, instantPurchaseMax: Price, encryptWallet: () => void, decryptWallet: () => void, updateWalletStatus: () => void, walletEncrypted: boolean, hideBalance: boolean, confirmForgetPassword: ({}) => void, ffmpegStatus: { available: boolean, which: string }, findingFFmpeg: boolean, findFFmpeg: () => void, language?: string, syncEnabled: boolean, syncSettings: () => void, }; type State = { clearingCache: boolean, storedPassword: boolean, }; class SettingsPage extends React.PureComponent { constructor(props: Props) { super(props); this.state = { clearingCache: false, storedPassword: false, }; (this: any).onKeyFeeChange = this.onKeyFeeChange.bind(this); (this: any).onMaxConnectionsChange = this.onMaxConnectionsChange.bind(this); (this: any).onKeyFeeDisableChange = this.onKeyFeeDisableChange.bind(this); (this: any).onInstantPurchaseMaxChange = this.onInstantPurchaseMaxChange.bind(this); (this: any).onThemeChange = this.onThemeChange.bind(this); (this: any).onAutomaticDarkModeChange = this.onAutomaticDarkModeChange.bind(this); (this: any).onConfirmForgetPassword = this.onConfirmForgetPassword.bind(this); (this: any).onDone = this.onDone.bind(this); } componentDidMount() { const { isAuthenticated, ffmpegStatus, daemonSettings, findFFmpeg } = this.props; // @if TARGET='app' const { available } = ffmpegStatus; const { ffmpeg_path: ffmpegPath } = daemonSettings; if (!available) { if (ffmpegPath) { this.clearDaemonSetting('ffmpeg_path'); } findFFmpeg(); } // @endif if (isAuthenticated || !IS_WEB) { this.props.updateWalletStatus(); getPasswordFromCookie().then(p => { if (typeof p === 'string') { this.setState({ storedPassword: true }); } }); } } onDone() { const { syncSettings } = this.props; if (this.props.syncEnabled) { syncSettings(); } } onFFmpegFolder(path: string) { this.setDaemonSetting('ffmpeg_path', path); this.findFFmpeg(); } onKeyFeeChange(newValue: Price) { this.setDaemonSetting('max_key_fee', newValue); } onMaxConnectionsChange(event: SyntheticInputEvent<*>) { const { value } = event.target; this.setDaemonSetting('max_connections_per_download', value); } onKeyFeeDisableChange(isDisabled: boolean) { if (isDisabled) this.setDaemonSetting('max_key_fee'); } 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); } onInstantPurchaseEnabledChange(enabled: boolean) { this.props.setClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED, enabled); } onInstantPurchaseMaxChange(newValue: Price) { this.props.setClientSetting(SETTINGS.INSTANT_PURCHASE_MAX, newValue); } onChangeEncryptWallet() { const { decryptWallet, walletEncrypted, encryptWallet } = this.props; if (walletEncrypted) { decryptWallet(); } else { encryptWallet(); } } onConfirmForgetPassword() { const { confirmForgetPassword } = this.props; confirmForgetPassword({ callback: () => { this.setState({ storedPassword: false }); }, }); } setDaemonSetting(name: string, value: ?SetDaemonSettingArg): void { this.props.setDaemonSetting(name, value); } clearDaemonSetting(name: string): void { this.props.clearDaemonSetting(name); } findFFmpeg(): void { this.props.findFFmpeg(); } render() { const { daemonSettings, ffmpegStatus, instantPurchaseEnabled, instantPurchaseMax, isAuthenticated, walletEncrypted, setDaemonSetting, setClientSetting, hideBalance, findingFFmpeg, language, } = this.props; const { storedPassword } = this.state; const noDaemonSettings = !daemonSettings || Object.keys(daemonSettings).length === 0; const defaultMaxKeyFee = { currency: 'USD', amount: 50 }; const disableMaxKeyFee = !(daemonSettings && daemonSettings.max_key_fee); const connectionOptions = [1, 2, 4, 6, 10, 20]; // @if TARGET='app' const { available: ffmpegAvailable, which: ffmpegPath } = ffmpegStatus; // @endif return ( this.onDone(), title: __('Advanced Settings'), backLabel: __('Done'), }} className="card-stack" > {!IS_WEB && noDaemonSettings ? (
{__('Failed to load settings.')}
) : (
{/* @if TARGET='app' */} setDaemonSetting('save_files', !daemonSettings.save_files)} checked={daemonSettings.save_files} label={__('Save all viewed content to your downloads directory')} helper={__( 'Paid content and some file types are saved by default. Changing this setting will not affect previously downloaded content.' )} /> setDaemonSetting('save_blobs', !daemonSettings.save_blobs)} checked={daemonSettings.save_blobs} label={__('Save hosting data to help the LBRY network')} helper={ {__("If disabled, LBRY will be very sad and you won't be helping improve the network.")}{' '}
)}
); } } export default SettingsPage;