// @flow /* eslint react/no-unescaped-entities:0 */ /* eslint react/jsx-no-comment-textnodes:0 */ import * as SETTINGS from 'constants/settings'; import * as PAGES from 'constants/pages'; 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 SettingLanguage from 'component/settingLanguage'; import SettingWalletServer from 'component/settingWalletServer'; import SettingAutoLaunch from 'component/settingAutoLaunch'; import FileSelector from 'component/common/file-selector'; import SyncToggle from 'component/syncToggle'; import Card from 'component/common/card'; import { getSavedPassword } from 'util/saved-passwords'; // @if TARGET='app' export const IS_MAC = process.platform === 'darwin'; // @endif type Price = { currency: string, amount: number, }; type SetDaemonSettingArg = boolean | string | number | Price; type DarkModeTimes = { from: { hour: string, min: string, formattedTime: string }, to: { hour: string, min: string, formattedTime: string }, }; type OptionTimes = { fromTo: string, time: string, }; type DaemonSettings = { download_dir: string, share_usage_data: boolean, max_key_fee?: Price, max_connections_per_download?: number, save_files: boolean, save_blobs: boolean, }; type Props = { setDaemonSetting: (string, ?SetDaemonSettingArg) => void, setClientSetting: (string, SetDaemonSettingArg) => void, clearCache: () => Promise, daemonSettings: DaemonSettings, showNsfw: boolean, isAuthenticated: 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, supportOption: boolean, userBlockedChannelsCount?: number, hideBalance: boolean, confirmForgetPassword: ({}) => void, floatingPlayer: boolean, clearPlayingUri: () => void, darkModeTimes: DarkModeTimes, setDarkTime: (string, {}) => 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).onChangeTime = this.onChangeTime.bind(this); (this: any).onConfirmForgetPassword = this.onConfirmForgetPassword.bind(this); } componentDidMount() { const { isAuthenticated } = this.props; if (isAuthenticated) { this.props.updateWalletStatus(); getSavedPassword().then(p => { if (p) { this.setState({ storedPassword: true }); } }); } } 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 }); }, }); } onChangeTime(event: SyntheticInputEvent<*>, options: OptionTimes) { const { value } = event.target; this.props.setDarkTime(value, options); } to12Hour(time: string) { const now = new Date(0, 0, 0, Number(time)); const hour = now.toLocaleTimeString('en-US', { hour12: true, hour: '2-digit' }); return hour; } setDaemonSetting(name: string, value: ?SetDaemonSettingArg): void { this.props.setDaemonSetting(name, value); } render() { const { daemonSettings, showNsfw, instantPurchaseEnabled, instantPurchaseMax, isAuthenticated, currentTheme, themes, automaticDarkModeEnabled, autoplay, walletEncrypted, osNotificationsEnabled, // autoDownload, setDaemonSetting, setClientSetting, supportOption, hideBalance, userBlockedChannelsCount, floatingPlayer, clearPlayingUri, darkModeTimes, clearCache, } = 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]; const startHours = ['18', '19', '20', '21']; const endHours = ['5', '6', '7', '8']; return ( {!IS_WEB && noDaemonSettings ? (
{__('Failed to load settings.')}
) : (
} /> {/* @if TARGET='app' */} } /> { setDaemonSetting('download_dir', newDirectory.path); }} />

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

} /> 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;