// @flow import { ALERT } from 'constants/icons'; 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 SettingsRow from 'component/settingsRow'; import SettingWalletServer from 'component/settingWalletServer'; import Spinner from 'component/spinner'; import { getPasswordFromCookie } from 'util/saved-passwords'; // @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 = { // --- select --- daemonSettings: DaemonSettings, ffmpegStatus: { available: boolean, which: string }, findingFFmpeg: boolean, walletEncrypted: boolean, isAuthenticated: boolean, // --- perform --- setDaemonSetting: (string, ?SetDaemonSettingArg) => void, clearDaemonSetting: (string) => void, clearCache: () => Promise, findFFmpeg: () => void, encryptWallet: () => void, decryptWallet: () => void, updateWalletStatus: () => void, confirmForgetPassword: ({}) => void, }; export default function SettingSystem(props: Props) { const { daemonSettings, ffmpegStatus, findingFFmpeg, walletEncrypted, isAuthenticated, setDaemonSetting, clearDaemonSetting, clearCache, findFFmpeg, encryptWallet, decryptWallet, updateWalletStatus, confirmForgetPassword, } = props; const [clearingCache, setClearingCache] = React.useState(false); const [storedPassword, setStoredPassword] = React.useState(false); // @if TARGET='app' const { available: ffmpegAvailable, which: ffmpegPath } = ffmpegStatus; // @endif function onChangeEncryptWallet() { if (walletEncrypted) { decryptWallet(); } else { encryptWallet(); } } function onConfirmForgetPassword() { confirmForgetPassword({ callback: () => setStoredPassword(false) }); } // Update ffmpeg variables React.useEffect(() => { // @if TARGET='app' const { available } = ffmpegStatus; const { ffmpeg_path: ffmpegPath } = daemonSettings; if (!available) { if (ffmpegPath) { clearDaemonSetting('ffmpeg_path'); } findFFmpeg(); } // @endif }, []); // eslint-disable-line react-hooks/exhaustive-deps // Update storedPassword state React.useEffect(() => { if (isAuthenticated || !IS_WEB) { updateWalletStatus(); getPasswordFromCookie().then((p) => { if (typeof p === 'string') { setStoredPassword(true); } }); } }, []); // eslint-disable-line react-hooks/exhaustive-deps return ( {/* @if TARGET='app' */} { setDaemonSetting('download_dir', newDirectory.path); }} /> {/* @endif */} {/* @if TARGET='app' */} setDaemonSetting('save_files', !daemonSettings.save_files)} checked={daemonSettings.save_files} /> {__("If disabled, LBRY will be very sad and you won't be helping improve the network.")}{' '}