2021-08-05 10:41:45 +02:00
// @flow
import { ALERT } from 'constants/icons' ;
2021-08-08 10:13:35 +02:00
import { SETTINGS _GRP } from 'constants/settings' ;
2021-08-05 10:41:45 +02:00
import React from 'react' ;
import Button from 'component/button' ;
import Card from 'component/common/card' ;
2021-08-06 10:25:37 +02:00
import { FormField } from 'component/common/form' ;
2021-08-07 15:35:11 +02:00
import FileSelector from 'component/common/file-selector' ;
import I18nMessage from 'component/i18nMessage' ;
2021-08-05 10:41:45 +02:00
import SettingAutoLaunch from 'component/settingAutoLaunch' ;
import SettingClosingBehavior from 'component/settingClosingBehavior' ;
2021-08-07 15:12:07 +02:00
import SettingCommentsServer from 'component/settingCommentsServer' ;
2021-10-22 04:41:45 +02:00
import SettingShareUrl from 'component/settingShareUrl' ;
2021-08-05 10:41:45 +02:00
import SettingsRow from 'component/settingsRow' ;
2021-08-07 15:12:07 +02:00
import SettingWalletServer from 'component/settingWalletServer' ;
2021-08-07 15:35:11 +02:00
import Spinner from 'component/spinner' ;
2021-08-08 04:26:40 +02:00
import { getPasswordFromCookie } from 'util/saved-passwords' ;
2021-10-28 01:21:16 +02:00
import * as DAEMON _SETTINGS from 'constants/daemon_settings' ;
2021-12-15 21:58:47 +01:00
import SettingEnablePrereleases from 'component/settingEnablePrereleases' ;
2022-02-18 19:44:00 +01:00
import SettingDisableAutoUpdates from 'component/settingDisableAutoUpdates' ;
2021-08-05 10:41:45 +02:00
const IS _MAC = process . platform === 'darwin' ;
2021-08-06 10:25:37 +02:00
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 ,
} ;
2021-08-05 10:41:45 +02:00
type Props = {
2021-08-07 15:35:11 +02:00
// --- select ---
2021-08-06 10:25:37 +02:00
daemonSettings : DaemonSettings ,
2021-08-07 15:35:11 +02:00
ffmpegStatus : { available : boolean , which : string } ,
findingFFmpeg : boolean ,
2021-08-08 04:26:40 +02:00
walletEncrypted : boolean ,
isAuthenticated : boolean ,
2021-08-08 05:13:04 +02:00
allowAnalytics : boolean ,
2021-08-07 15:35:11 +02:00
// --- perform ---
2021-08-06 10:25:37 +02:00
setDaemonSetting : ( string , ? SetDaemonSettingArg ) => void ,
2021-08-07 15:35:11 +02:00
clearDaemonSetting : ( string ) => void ,
2021-08-05 10:41:45 +02:00
clearCache : ( ) => Promise < any > ,
2021-08-07 15:35:11 +02:00
findFFmpeg : ( ) => void ,
2021-08-08 04:26:40 +02:00
encryptWallet : ( ) => void ,
decryptWallet : ( ) => void ,
updateWalletStatus : ( ) => void ,
confirmForgetPassword : ( { } ) => void ,
2021-08-08 05:13:04 +02:00
toggle3PAnalytics : ( boolean ) => void ,
2021-08-05 10:41:45 +02:00
} ;
export default function SettingSystem ( props : Props ) {
2021-08-07 15:35:11 +02:00
const {
daemonSettings ,
ffmpegStatus ,
findingFFmpeg ,
2021-08-08 04:26:40 +02:00
walletEncrypted ,
isAuthenticated ,
2021-08-08 05:13:04 +02:00
allowAnalytics ,
2021-08-07 15:35:11 +02:00
setDaemonSetting ,
clearDaemonSetting ,
clearCache ,
findFFmpeg ,
2021-08-08 04:26:40 +02:00
encryptWallet ,
decryptWallet ,
updateWalletStatus ,
confirmForgetPassword ,
2021-08-08 05:13:04 +02:00
toggle3PAnalytics ,
2021-08-07 15:35:11 +02:00
} = props ;
2021-08-08 04:26:40 +02:00
2021-08-05 10:41:45 +02:00
const [ clearingCache , setClearingCache ] = React . useState ( false ) ;
2021-08-08 04:26:40 +02:00
const [ storedPassword , setStoredPassword ] = React . useState ( false ) ;
2021-08-07 15:35:11 +02:00
const { available : ffmpegAvailable , which : ffmpegPath } = ffmpegStatus ;
2021-08-08 04:26:40 +02:00
function onChangeEncryptWallet ( ) {
if ( walletEncrypted ) {
decryptWallet ( ) ;
} else {
encryptWallet ( ) ;
}
}
function onConfirmForgetPassword ( ) {
confirmForgetPassword ( { callback : ( ) => setStoredPassword ( false ) } ) ;
}
// Update ffmpeg variables
2021-08-07 15:35:11 +02:00
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
2021-08-08 04:26:40 +02:00
// Update storedPassword state
React . useEffect ( ( ) => {
2022-01-07 20:02:33 +01:00
updateWalletStatus ( ) ;
getPasswordFromCookie ( ) . then ( ( p ) => {
if ( typeof p === 'string' ) {
setStoredPassword ( true ) ;
}
} ) ;
2021-08-08 04:26:40 +02:00
} , [ ] ) ; // eslint-disable-line react-hooks/exhaustive-deps
2021-08-05 10:41:45 +02:00
return (
2021-08-09 04:22:16 +02:00
< >
< div className = "card__title-section" >
< h2 className = "card__title" > { _ _ ( 'System' ) } < / h2 >
< / div >
< Card
id = { SETTINGS _GRP . SYSTEM }
isBodyList
body = {
< >
{ /* @if TARGET='app' */ }
< SettingsRow title = { _ _ ( 'Download directory' ) } subtitle = { _ _ ( 'LBRY downloads will be saved here.' ) } >
< FileSelector
type = "openDirectory"
currentPath = { daemonSettings . download _dir }
2022-09-02 18:43:35 +02:00
onFileChosen = { ( newDirectory : FileWithPath ) => {
2021-08-09 04:22:16 +02:00
setDaemonSetting ( 'download_dir' , newDirectory . path ) ;
} }
/ >
< / SettingsRow >
{ /* @endif */ }
2021-08-08 05:13:04 +02:00
2021-08-06 10:25:37 +02:00
< SettingsRow
2021-08-09 04:22:16 +02:00
title = { _ _ ( 'Save all viewed content to your downloads directory' ) }
2021-08-06 10:25:37 +02:00
subtitle = { _ _ (
2021-08-09 04:22:16 +02:00
'Paid content and some file types are saved by default. Changing this setting will not affect previously downloaded content.'
2021-08-06 10:25:37 +02:00
) }
>
2021-08-09 04:22:16 +02:00
< FormField
type = "checkbox"
name = "save_files"
onChange = { ( ) => setDaemonSetting ( 'save_files' , ! daemonSettings . save _files ) }
checked = { daemonSettings . save _files }
/ >
< / SettingsRow >
< SettingsRow
title = { _ _ ( 'Share usage and diagnostic data' ) }
subtitle = {
< React.Fragment >
{ _ _ (
2021-11-28 21:05:10 +01:00
` This is information like error logging, performance tracking, and usage statistics. It includes your IP address and basic system details, but no other identifying information (unless you connect to a cloud service) `
2021-08-09 04:22:16 +02:00
) } { ' ' }
2021-10-11 03:43:29 +02:00
< Button button = "link" label = { _ _ ( 'Learn more' ) } href = "https://lbry.com/privacypolicy" / >
2021-08-09 04:22:16 +02:00
< / React.Fragment >
}
2021-08-22 09:58:56 +02:00
multirow
2021-08-09 04:22:16 +02:00
>
< FormField
type = "checkbox"
name = "share_internal"
onChange = { ( ) => setDaemonSetting ( 'share_usage_data' , ! daemonSettings . share _usage _data ) }
checked = { daemonSettings . share _usage _data }
label = { < React.Fragment > { _ _ ( 'Allow the app to share data to LBRY.inc' ) } < / React.Fragment > }
helper = {
isAuthenticated
? _ _ ( 'Internal sharing is required while signed in.' )
: _ _ ( 'Internal sharing is required to participate in rewards programs.' )
}
disabled = { isAuthenticated && daemonSettings . share _usage _data }
/ >
< FormField
type = "checkbox"
name = "share_third_party"
onChange = { ( e ) => toggle3PAnalytics ( e . target . checked ) }
checked = { allowAnalytics }
label = { _ _ ( 'Allow the app to access third party analytics platforms' ) }
helper = { _ _ ( 'We use detailed analytics to improve all aspects of the LBRY experience.' ) }
/ >
< / SettingsRow >
{ /* Auto launch in a hidden state doesn't work on mac https://github.com/Teamwork/node-auto-launch/issues/81 */ }
{ ! IS _MAC && (
< SettingsRow
title = { _ _ ( 'Start minimized' ) }
subtitle = { _ _ (
'Improve view speed and help the LBRY network by allowing the app to cuddle up in your system tray.'
) }
>
< SettingAutoLaunch noLabels / >
< / SettingsRow >
) }
< SettingsRow title = { _ _ ( 'Leave app running in notification area when the window is closed' ) } >
< SettingClosingBehavior noLabels / >
< / SettingsRow >
2021-12-15 21:58:47 +01:00
< SettingsRow
title = { _ _ ( 'Enable Upgrade to Test Builds' ) }
subtitle = { _ _ ( 'Prereleases may break things and we may not be able to fix them for you.' ) }
>
< SettingEnablePrereleases / >
< / SettingsRow >
2022-02-18 19:44:00 +01:00
< SettingsRow
title = { _ _ ( 'Disable automatic updates' ) }
subtitle = { _ _ (
"Preven't new updates to be downloaded automatically in the background (we will keep notifying you if there is an update)"
) }
>
< SettingDisableAutoUpdates / >
< / SettingsRow >
2021-08-09 04:22:16 +02:00
< SettingsRow
title = {
< span >
{ _ _ ( 'Automatic transcoding' ) }
{ findingFFmpeg && < Spinner type = "small" / > }
< / span >
}
>
< FileSelector
type = "openDirectory"
placeholder = { _ _ ( 'A Folder containing FFmpeg' ) }
currentPath = { ffmpegPath || daemonSettings . ffmpeg _path }
2022-09-02 18:43:35 +02:00
onFileChosen = { ( newDirectory : FileWithPath ) => {
2021-08-09 04:22:16 +02:00
// $FlowFixMe
setDaemonSetting ( 'ffmpeg_path' , newDirectory . path ) ;
findFFmpeg ( ) ;
} }
disabled = { Boolean ( ffmpegPath ) }
/ >
< p className = "help" >
{ ffmpegAvailable ? (
2021-08-08 04:26:40 +02:00
< I18nMessage
tokens = { {
learn _more : (
2021-08-09 04:22:16 +02:00
< Button
button = "link"
label = { _ _ ( 'Learn more' ) }
href = "https://lbry.com/faq/video-publishing-guide#automatic"
/ >
2021-08-08 04:26:40 +02:00
) ,
} }
>
2021-08-09 04:22:16 +02:00
FFmpeg is correctly configured . % learn _more %
2021-08-08 04:26:40 +02:00
< / I18nMessage >
2021-08-09 04:22:16 +02:00
) : (
< I18nMessage
tokens = { {
check _again : (
< Button
button = "link"
label = { _ _ ( 'Check again' ) }
onClick = { ( ) => findFFmpeg ( ) }
disabled = { findingFFmpeg }
/ >
) ,
learn _more : (
< Button
button = "link"
label = { _ _ ( 'Learn more' ) }
href = "https://lbry.com/faq/video-publishing-guide#automatic"
/ >
) ,
} }
>
FFmpeg could not be found . Navigate to it or Install , Then % check _again % or quit and restart the
app . % learn _more %
< / I18nMessage >
) }
< / p >
< / SettingsRow >
2021-08-22 09:58:56 +02:00
< SettingsRow
title = { _ _ ( 'Encrypt my wallet with a custom password' ) }
subtitle = {
< React.Fragment >
< I18nMessage
tokens = { {
learn _more : (
< Button button = "link" label = { _ _ ( 'Learn more' ) } href = "https://lbry.com/faq/account-sync" / >
) ,
} }
>
Wallet encryption is currently unavailable until it ' s supported for synced accounts . It will be
added back soon . % learn _more % .
< / I18nMessage >
{ / * { _ _ ( ' S e c u r e y o u r l o c a l w a l l e t d a t a w i t h a c u s t o m p a s s w o r d . ' ) } { ' ' }
< strong > { _ _ ( 'Lost passwords cannot be recovered.' ) } < / strong >
< Button button = "link" label = { _ _ ( 'Learn more' ) } href = "https://lbry.com/faq/wallet-encryption" / > . * / }
< / React.Fragment >
}
>
2021-08-08 04:26:40 +02:00
< FormField
2021-08-09 04:22:16 +02:00
disabled
2021-08-08 04:26:40 +02:00
type = "checkbox"
2021-08-09 04:22:16 +02:00
name = "encrypt_wallet"
onChange = { ( ) => onChangeEncryptWallet ( ) }
checked = { walletEncrypted }
2021-08-08 04:26:40 +02:00
/ >
2021-08-22 09:58:56 +02:00
< / SettingsRow >
2021-08-08 04:26:40 +02:00
2021-08-22 09:58:56 +02:00
{ walletEncrypted && storedPassword && (
< SettingsRow
title = { _ _ ( 'Save wallet password' ) }
subtitle = { _ _ ( 'Automatically unlock your wallet on startup' ) }
>
2021-08-09 04:22:16 +02:00
< FormField
type = "checkbox"
name = "save_password"
onChange = { onConfirmForgetPassword }
checked = { storedPassword }
/ >
2021-08-22 09:58:56 +02:00
< / SettingsRow >
) }
< SettingsRow
title = { _ _ ( 'Max connections' ) }
subtitle = { _ _ (
'For users with good bandwidth, try a higher value to improve streaming and download speeds. Low bandwidth users may benefit from a lower setting. Default is 4.'
) }
>
2021-08-09 04:22:16 +02:00
{ /* Disabling below until we get downloads to work with shared subscriptions code */ }
{ / *
2021-08-07 15:12:07 +02:00
< FormField
type = "checkbox"
name = "auto_download"
onChange = { ( ) => setClientSetting ( SETTINGS . AUTO _DOWNLOAD , ! autoDownload ) }
checked = { autoDownload }
label = { _ _ ( 'Automatically download new content from my subscriptions' ) }
helper = { _ _ (
"The latest file from each of your subscriptions will be downloaded for quick access as soon as it's published."
) }
/ >
* / }
2021-08-09 04:22:16 +02:00
< fieldset - section >
< FormField
name = "max_connections"
type = "select"
min = { 1 }
max = { 100 }
2021-10-28 01:21:16 +02:00
onChange = { ( e ) => setDaemonSetting ( DAEMON _SETTINGS . MAX _CONNECTIONS _PER _DOWNLOAD , e . target . value ) }
value = { daemonSettings [ DAEMON _SETTINGS . MAX _CONNECTIONS _PER _DOWNLOAD ] }
2021-08-09 04:22:16 +02:00
>
{ [ 1 , 2 , 4 , 6 , 10 , 20 ] . map ( ( connectionOption ) => (
< option key = { connectionOption } value = { connectionOption } >
{ connectionOption }
< / option >
) ) }
< / FormField >
< / f i e l d s e t - s e c t i o n >
2021-08-22 09:58:56 +02:00
< / SettingsRow >
2021-08-07 15:12:07 +02:00
2022-02-04 21:40:00 +01:00
< SettingsRow
title = { _ _ ( 'Wallet server' ) }
subtitle = {
< I18nMessage
tokens = { {
learn _more : (
< Button button = "link" href = "http://lbry.com/faq/wallet-servers" label = { _ _ ( 'Learn More' ) } / >
) ,
} }
>
Wallet servers are used to relay data to and from the LBRY blockchain . They also determine what
content shows in trending or is blocked . % learn _more %
< / I18nMessage >
}
multirow
>
2021-08-09 04:22:16 +02:00
< SettingWalletServer / >
2021-08-22 09:58:56 +02:00
< / SettingsRow >
< SettingsRow title = { _ _ ( 'Comments server' ) } multirow >
2021-08-09 04:22:16 +02:00
< SettingCommentsServer / >
< / SettingsRow >
2021-10-22 04:41:45 +02:00
< SettingsRow title = { _ _ ( 'Share url' ) } multirow >
< SettingShareUrl / >
< / SettingsRow >
2021-08-09 04:22:16 +02:00
< SettingsRow
title = { _ _ ( 'Clear application cache' ) }
subtitle = { _ _ ( 'This might fix issues that you are having. Your wallet will not be affected.' ) }
>
< Button
2022-04-17 19:04:56 +02:00
button = "primary"
2021-08-09 04:22:16 +02:00
icon = { ALERT }
label = { clearingCache ? _ _ ( 'Clearing' ) : _ _ ( 'Clear Cache' ) }
onClick = { ( ) => {
setClearingCache ( true ) ;
clearCache ( ) ;
} }
disabled = { clearingCache }
/ >
< / SettingsRow >
< / >
}
/ >
< / >
2021-08-05 10:41:45 +02:00
) ;
}