// @flow import { ALERT } from 'constants/icons'; import { SETTINGS_GRP } from 'constants/settings'; import React from 'react'; import Button from 'component/button'; import Card from 'component/common/card'; import { FormField } from 'component/common/form'; import FileSelector from 'component/common/file-selector'; import I18nMessage from 'component/i18nMessage'; import SettingAutoLaunch from 'component/settingAutoLaunch'; import SettingClosingBehavior from 'component/settingClosingBehavior'; import SettingCommentsServer from 'component/settingCommentsServer'; import SettingShareUrl from 'component/settingShareUrl'; import SettingsRow from 'component/settingsRow'; import SettingWalletServer from 'component/settingWalletServer'; import Spinner from 'component/spinner'; import { getPasswordFromCookie } from 'util/saved-passwords'; import * as DAEMON_SETTINGS from 'constants/daemon_settings'; import { formatBytes } from 'util/format-bytes'; import SettingEnablePrereleases from 'component/settingEnablePrereleases'; const IS_MAC = process.platform === 'darwin'; const BYTES_PER_MB = 1048576; 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 DaemonStatus = { disk_space: { content_blobs_storage_used_mb: string, published_blobs_storage_used_mb: string, running: true, seed_blobs_storage_used_mb: string, total_used_mb: string, }, }; type Props = { // --- select --- daemonSettings: DaemonSettings, ffmpegStatus: { available: boolean, which: string }, findingFFmpeg: boolean, walletEncrypted: boolean, isAuthenticated: boolean, allowAnalytics: boolean, // --- perform --- setDaemonSetting: (string, ?SetDaemonSettingArg) => void, clearDaemonSetting: (string) => void, clearCache: () => Promise, findFFmpeg: () => void, encryptWallet: () => void, decryptWallet: () => void, updateWalletStatus: () => void, confirmForgetPassword: ({}) => void, toggle3PAnalytics: (boolean) => void, daemonStatus: DaemonStatus, }; export default function SettingSystem(props: Props) { const { daemonSettings, ffmpegStatus, findingFFmpeg, walletEncrypted, isAuthenticated, allowAnalytics, setDaemonSetting, clearDaemonSetting, clearCache, findFFmpeg, encryptWallet, decryptWallet, updateWalletStatus, confirmForgetPassword, toggle3PAnalytics, daemonStatus, } = props; const [clearingCache, setClearingCache] = React.useState(false); const [storedPassword, setStoredPassword] = React.useState(false); const { disk_space } = daemonStatus; const contentSpaceUsed = Number(disk_space.content_blobs_storage_used_mb); const networkSpaceUsed = Number(disk_space.seed_blobs_storage_used_mb); const blobLimitSetting = daemonSettings[DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB]; const networkLimitSetting = daemonSettings[DAEMON_SETTINGS.NETWORK_STORAGE_LIMIT_MB]; const [contentBlobSpaceLimitGB, setContentBlobSpaceLimit] = React.useState( blobLimitSetting ? blobLimitSetting / 1024 : 0 ); const [networkBlobSpaceLimitGB, setNetworkBlobSpaceLimit] = React.useState( networkLimitSetting ? networkLimitSetting / 1024 : 0 ); const [limitSpace, setLimitSpace] = React.useState(Boolean(blobLimitSetting)); const { available: ffmpegAvailable, which: ffmpegPath } = ffmpegStatus; function onChangeEncryptWallet() { if (walletEncrypted) { decryptWallet(); } else { encryptWallet(); } } function onConfirmForgetPassword() { confirmForgetPassword({ callback: () => setStoredPassword(false) }); } function updateContentBlobLimitField(gb) { if (gb === 0) { setContentBlobSpaceLimit(0); } else if (!gb || !isNaN(gb)) { setContentBlobSpaceLimit(gb); } } function updateNetworkBlobLimitField(gb) { if (gb === 0) { setNetworkBlobSpaceLimit(0); } else if (!gb || !isNaN(gb)) { setNetworkBlobSpaceLimit(gb); } } function handleLimitSpace(value) { setLimitSpace(value); if (!value) { setDaemonSetting(DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB, String(0)); } else { const spaceLimitMB = contentBlobSpaceLimitGB * 1024; setDaemonSetting(DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB, String(spaceLimitMB)); } } function handleSetContentBlobSpaceLimit() { const spaceLimitMB = contentBlobSpaceLimitGB * 1024; if (!isNaN(spaceLimitMB) && blobLimitSetting !== spaceLimitMB * 1024) { setDaemonSetting(DAEMON_SETTINGS.BLOB_STORAGE_LIMIT_MB, String(spaceLimitMB)); } } function handleSetNetworkBlobSpaceLimit() { const spaceLimitMB = networkBlobSpaceLimitGB * 1024; if (!isNaN(spaceLimitMB) && blobLimitSetting !== spaceLimitMB * 1024) { setDaemonSetting(DAEMON_SETTINGS.NETWORK_STORAGE_LIMIT_MB, String(spaceLimitMB)); } } // Update ffmpeg variables React.useEffect(() => { const { available } = ffmpegStatus; const { ffmpeg_path: ffmpegPath } = daemonSettings; if (!available) { if (ffmpegPath) { clearDaemonSetting('ffmpeg_path'); } findFFmpeg(); } }, []); // eslint-disable-line react-hooks/exhaustive-deps // Update storedPassword state React.useEffect(() => { updateWalletStatus(); getPasswordFromCookie().then((p) => { if (typeof p === 'string') { setStoredPassword(true); } }); }, []); // eslint-disable-line react-hooks/exhaustive-deps return ( <>

{__('System')}

{/* @if TARGET='app' */} { setDaemonSetting('download_dir', newDirectory.path); }} /> {/* @endif */} setDaemonSetting('save_files', !daemonSettings.save_files)} checked={daemonSettings.save_files} /> {__('Content Data Hosting helps to seed things that you watch and download.')}{' '} {__('Network Data Hosting allows the p2p network to store blobs unrelated to your browsing.')}{' '} {__("If disabled, LBRY will be very sad and you won't be helping improve the network.")}{' '} {__('If you set a limit, playing videos may exceed your limit until cleanup runs every 30 minutes.')}{' '}