2018-03-26 23:32:43 +02:00
// @flow
2018-11-26 02:21:25 +01:00
import * as ICONS from 'constants/icons' ;
import * as SETTINGS from 'constants/settings' ;
2018-03-26 23:32:43 +02:00
import * as React from 'react' ;
2019-01-09 05:29:06 +01:00
import { FormField , FormFieldPrice , FormRow } from 'component/common/form' ;
2018-03-26 23:32:43 +02:00
import Button from 'component/button' ;
import Page from 'component/page' ;
import FileSelector from 'component/common/file-selector' ;
export type Price = {
currency : string ,
amount : number ,
} ;
type DaemonSettings = {
download _directory : string ,
disable _max _key _fee : boolean ,
share _usage _data : boolean ,
2018-10-13 17:49:47 +02:00
max _key _fee ? : Price ,
2018-03-26 23:32:43 +02:00
} ;
type Props = {
setDaemonSetting : ( string , boolean | string | Price ) => void ,
2018-06-19 05:36:15 +02:00
setClientSetting : ( string , boolean | string | number | Price ) => void ,
2018-03-26 23:32:43 +02:00
clearCache : ( ) => Promise < any > ,
getThemes : ( ) => void ,
daemonSettings : DaemonSettings ,
showNsfw : boolean ,
instantPurchaseEnabled : boolean ,
instantPurchaseMax : Price ,
currentTheme : string ,
themes : Array < string > ,
automaticDarkModeEnabled : boolean ,
2018-05-30 05:18:41 +02:00
autoplay : boolean ,
2018-08-10 16:51:51 +02:00
autoDownload : boolean ,
2018-07-18 21:48:30 +02:00
encryptWallet : ( ) => void ,
decryptWallet : ( ) => void ,
2018-10-13 17:49:47 +02:00
updateWalletStatus : ( ) => void ,
2018-07-18 21:48:30 +02:00
walletEncrypted : boolean ,
2018-08-01 20:49:57 +02:00
osNotificationsEnabled : boolean ,
2018-03-26 23:32:43 +02:00
} ;
type State = {
clearingCache : boolean ,
} ;
class SettingsPage extends React . PureComponent < Props , State > {
constructor ( props : Props ) {
2017-05-17 10:10:25 +02:00
super ( props ) ;
2017-06-02 18:40:26 +02:00
2017-05-18 03:37:39 +02:00
this . state = {
2017-06-16 07:43:43 +02:00
clearingCache : false ,
2017-06-06 23:19:12 +02:00
} ;
2018-02-08 20:28:46 +01:00
2018-03-26 23:32:43 +02:00
( this : any ) . onDownloadDirChange = this . onDownloadDirChange . bind ( this ) ;
( this : any ) . onKeyFeeChange = this . onKeyFeeChange . bind ( this ) ;
( this : any ) . onInstantPurchaseMaxChange = this . onInstantPurchaseMaxChange . bind ( this ) ;
( this : any ) . onShowNsfwChange = this . onShowNsfwChange . bind ( this ) ;
( this : any ) . onShareDataChange = this . onShareDataChange . bind ( this ) ;
( this : any ) . onThemeChange = this . onThemeChange . bind ( this ) ;
( this : any ) . onAutomaticDarkModeChange = this . onAutomaticDarkModeChange . bind ( this ) ;
2018-04-30 17:27:20 +02:00
( this : any ) . onAutoplayChange = this . onAutoplayChange . bind ( this ) ;
2018-03-26 23:32:43 +02:00
( this : any ) . clearCache = this . clearCache . bind ( this ) ;
2018-07-31 02:13:57 +02:00
( this : any ) . onDesktopNotificationsChange = this . onDesktopNotificationsChange . bind ( this ) ;
2018-08-10 16:51:51 +02:00
( this : any ) . onAutoDownloadChange = this . onAutoDownloadChange . bind ( this ) ;
2018-03-26 23:32:43 +02:00
// (this: any).onLanguageChange = this.onLanguageChange.bind(this)
2017-06-16 07:43:43 +02:00
}
2018-03-26 23:32:43 +02:00
componentDidMount ( ) {
2018-10-13 17:49:47 +02:00
this . props . getThemes ( ) ;
this . props . updateWalletStatus ( ) ;
2017-05-17 10:10:25 +02:00
}
2018-03-26 23:32:43 +02:00
onRunOnStartChange ( event : SyntheticInputEvent < * > ) {
2017-12-21 22:08:54 +01:00
this . setDaemonSetting ( 'run_on_startup' , event . target . checked ) ;
2017-05-17 10:10:25 +02:00
}
2018-03-26 23:32:43 +02:00
onShareDataChange ( event : SyntheticInputEvent < * > ) {
2017-12-21 22:08:54 +01:00
this . setDaemonSetting ( 'share_usage_data' , event . target . checked ) ;
2017-05-17 10:10:25 +02:00
}
2018-03-26 23:32:43 +02:00
onDownloadDirChange ( newDirectory : string ) {
this . setDaemonSetting ( 'download_directory' , newDirectory ) ;
2017-05-17 10:10:25 +02:00
}
2018-03-26 23:32:43 +02:00
onKeyFeeChange ( newValue : Price ) {
this . setDaemonSetting ( 'max_key_fee' , newValue ) ;
2017-05-17 10:10:25 +02:00
}
2018-03-26 23:32:43 +02:00
onKeyFeeDisableChange ( isDisabled : boolean ) {
2017-12-21 22:08:54 +01:00
this . setDaemonSetting ( 'disable_max_key_fee' , isDisabled ) ;
2017-05-17 10:10:25 +02:00
}
2018-03-26 23:32:43 +02:00
onThemeChange ( event : SyntheticInputEvent < * > ) {
2017-08-12 20:46:10 +02:00
const { value } = event . target ;
2018-02-08 20:28:46 +01:00
if ( value === 'dark' ) {
this . onAutomaticDarkModeChange ( false ) ;
}
2018-11-26 02:21:25 +01:00
this . props . setClientSetting ( SETTINGS . THEME , value ) ;
2017-08-05 03:36:36 +02:00
}
2018-03-26 23:32:43 +02:00
onAutomaticDarkModeChange ( value : boolean ) {
2018-11-26 02:21:25 +01:00
this . props . setClientSetting ( SETTINGS . AUTOMATIC _DARK _MODE _ENABLED , value ) ;
2018-01-14 10:14:15 +01:00
}
2018-04-30 17:27:20 +02:00
onAutoplayChange ( event : SyntheticInputEvent < * > ) {
2018-11-26 02:21:25 +01:00
this . props . setClientSetting ( SETTINGS . AUTOPLAY , event . target . checked ) ;
2018-04-30 17:27:20 +02:00
}
2018-03-26 23:32:43 +02:00
onInstantPurchaseEnabledChange ( enabled : boolean ) {
2018-11-26 02:21:25 +01:00
this . props . setClientSetting ( SETTINGS . INSTANT _PURCHASE _ENABLED , enabled ) ;
2017-09-08 07:03:37 +02:00
}
2018-03-26 23:32:43 +02:00
onInstantPurchaseMaxChange ( newValue : Price ) {
2018-11-26 02:21:25 +01:00
this . props . setClientSetting ( SETTINGS . INSTANT _PURCHASE _MAX , newValue ) ;
2017-09-08 07:03:37 +02:00
}
2018-03-26 23:32:43 +02:00
onShowNsfwChange ( event : SyntheticInputEvent < * > ) {
2018-11-26 02:21:25 +01:00
this . props . setClientSetting ( SETTINGS . SHOW _NSFW , event . target . checked ) ;
2017-05-17 10:10:25 +02:00
}
2018-08-10 16:51:51 +02:00
onAutoDownloadChange ( event : SyntheticInputEvent < * > ) {
2018-11-26 02:21:25 +01:00
this . props . setClientSetting ( SETTINGS . AUTO _DOWNLOAD , event . target . checked ) ;
2018-08-10 16:51:51 +02:00
}
2018-07-18 21:48:30 +02:00
onChangeEncryptWallet ( ) {
2018-10-13 17:49:47 +02:00
const { decryptWallet , walletEncrypted , encryptWallet } = this . props ;
if ( walletEncrypted ) {
decryptWallet ( ) ;
} else {
encryptWallet ( ) ;
}
2017-08-24 18:29:54 +02:00
}
2018-07-31 02:13:57 +02:00
onDesktopNotificationsChange ( event : SyntheticInputEvent < * > ) {
2018-11-26 02:21:25 +01:00
this . props . setClientSetting ( SETTINGS . OS _NOTIFICATIONS _ENABLED , event . target . checked ) ;
2018-07-31 02:13:57 +02:00
}
2018-10-13 17:49:47 +02:00
setDaemonSetting ( name : string , value : boolean | string | Price ) {
this . props . setDaemonSetting ( name , value ) ;
}
2018-03-26 23:32:43 +02:00
clearCache ( ) {
this . setState ( {
clearingCache : true ,
} ) ;
const success = ( ) => {
this . setState ( { clearingCache : false } ) ;
window . location . href = 'index.html' ;
} ;
const clear = ( ) => this . props . clearCache ( ) . then ( success ) ;
setTimeout ( clear , 1000 , { once : true } ) ;
}
2017-08-07 05:01:10 +02:00
2017-05-17 10:10:25 +02:00
render ( ) {
2017-09-07 03:53:42 +02:00
const {
daemonSettings ,
showNsfw ,
2017-09-08 07:03:37 +02:00
instantPurchaseEnabled ,
instantPurchaseMax ,
2018-03-26 23:32:43 +02:00
currentTheme ,
2017-09-07 03:53:42 +02:00
themes ,
2018-01-14 10:14:15 +01:00
automaticDarkModeEnabled ,
2018-05-30 05:18:41 +02:00
autoplay ,
2018-07-18 21:48:30 +02:00
walletEncrypted ,
2018-08-01 20:49:57 +02:00
osNotificationsEnabled ,
2018-08-10 16:51:51 +02:00
autoDownload ,
2017-09-07 03:53:42 +02:00
} = this . props ;
2017-05-17 23:52:45 +02:00
2018-03-26 23:32:43 +02:00
const noDaemonSettings = ! daemonSettings || Object . keys ( daemonSettings ) . length === 0 ;
2018-05-06 22:40:30 +02:00
const isDarkModeEnabled = currentTheme === 'dark' ;
2018-02-08 20:28:46 +01:00
2016-04-10 02:00:56 +02:00
return (
2018-03-26 23:32:43 +02:00
< Page >
{ noDaemonSettings ? (
< section className = "card card--section" >
< div className = "card__title" > { _ _ ( 'Failed to load settings.' ) } < / div >
< / section >
) : (
< React.Fragment >
< section className = "card card--section" >
2018-12-19 06:44:53 +01:00
< header className = "card__header" >
< h2 className = "card__title" > { _ _ ( 'Download Directory' ) } < / h2 >
< p className = "card__subtitle" > { _ _ ( 'LBRY downloads will be saved here.' ) } < / p >
< / header >
2018-10-19 22:38:07 +02:00
< div className = "card__content" >
< FileSelector
type = "openDirectory"
currentPath = { daemonSettings . download _directory }
onFileChosen = { this . onDownloadDirChange }
/ >
< / div >
2018-03-26 23:32:43 +02:00
< / section >
2018-12-19 06:44:53 +01:00
2018-03-26 23:32:43 +02:00
< section className = "card card--section" >
2018-12-19 06:44:53 +01:00
< header className = "card__header" >
< h2 className = "card__title" > { _ _ ( 'Max Purchase Price' ) } < / h2 >
< p className = "card__subtitle" >
{ _ _ (
'This will prevent you from purchasing any content over a certain cost, as a safety measure.'
) }
< / p >
< / header >
2018-03-26 23:32:43 +02:00
< div className = "card__content" >
< FormField
type = "radio"
name = "no_max_purchase_limit"
checked = { daemonSettings . disable _max _key _fee }
postfix = { _ _ ( 'No Limit' ) }
onChange = { ( ) => {
this . onKeyFeeDisableChange ( true ) ;
} }
/ >
< FormField
type = "radio"
name = "max_purchase_limit"
onChange = { ( ) => {
this . onKeyFeeDisableChange ( false ) ;
} }
checked = { ! daemonSettings . disable _max _key _fee }
postfix = { _ _ ( 'Choose limit' ) }
/ >
2018-04-11 00:05:30 +02:00
{ ! daemonSettings . disable _max _key _fee && (
< FormFieldPrice
name = "max_key_fee"
label = "Max purchase price"
min = { 0 }
onChange = { this . onKeyFeeChange }
price = {
daemonSettings . max _key _fee
? daemonSettings . max _key _fee
: { currency : 'USD' , amount : 50 }
}
/ >
) }
2018-03-26 23:32:43 +02:00
< / div >
< / section >
2018-12-19 06:44:53 +01:00
2018-03-26 23:32:43 +02:00
< section className = "card card--section" >
2018-12-19 06:44:53 +01:00
< header className = "card__header" >
< h2 className = "card__title" > { _ _ ( 'Purchase Confirmations' ) } < / h2 >
< p className = "card__subtitle" >
{ _ _ (
"When this option is chosen, LBRY won't ask you to confirm downloads below your chosen price."
) }
< / p >
< / header >
2018-03-26 23:32:43 +02:00
< div className = "card__content" >
< FormField
type = "radio"
name = "confirm_all_purchases"
checked = { ! instantPurchaseEnabled }
postfix = { _ _ ( 'Always confirm before purchasing content' ) }
onChange = { ( ) => {
this . onInstantPurchaseEnabledChange ( false ) ;
} }
/ >
< FormField
type = "radio"
name = "instant_purchases"
checked = { instantPurchaseEnabled }
postfix = { _ _ ( 'Only confirm purchases over a certain price' ) }
onChange = { ( ) => {
this . onInstantPurchaseEnabledChange ( true ) ;
} }
/ >
2018-04-11 00:05:30 +02:00
{ instantPurchaseEnabled && (
< FormFieldPrice
label = { _ _ ( 'Confirmation price' ) }
min = { 0.1 }
onChange = { this . onInstantPurchaseMaxChange }
price = { instantPurchaseMax }
/ >
) }
2018-03-26 23:32:43 +02:00
< / div >
< / section >
2018-12-19 06:44:53 +01:00
2018-03-26 23:32:43 +02:00
< section className = "card card--section" >
2018-12-19 06:44:53 +01:00
< header className = "card__header" >
< h2 className = "card__title" > { _ _ ( 'Content Settings' ) } < / h2 >
< / header >
< div className = "card__content" >
2019-01-09 05:29:06 +01:00
< FormRow >
< FormField
type = "checkbox"
name = "show_nsfw"
onChange = { this . onShowNsfwChange }
checked = { showNsfw }
postfix = { _ _ ( 'Show NSFW content' ) }
helper = { _ _ (
'NSFW content may include nudity, intense sexuality, profanity, or other adult content. By displaying NSFW content, you are affirming you are of legal age to view mature content in your country or jurisdiction. '
) }
/ >
< / FormRow >
2018-12-19 06:44:53 +01:00
< / div >
2018-03-26 23:32:43 +02:00
< / section >
2018-08-01 00:42:54 +02:00
< section className = "card card--section" >
2018-12-19 06:44:53 +01:00
< header className = "card__header" >
< h2 className = "card__title" > { _ _ ( 'Notifications' ) } < / h2 >
< / header >
< div className = "card__content" >
< FormField
type = "checkbox"
name = "desktopNotification"
onChange = { this . onDesktopNotificationsChange }
checked = { osNotificationsEnabled }
postfix = { _ _ ( 'Show Desktop Notifications' ) }
/ >
< / div >
2018-08-01 00:42:54 +02:00
< / section >
2018-03-26 23:32:43 +02:00
< section className = "card card--section" >
2018-12-19 06:44:53 +01:00
< header className = "card__header" >
< h2 className = "card__title" > { _ _ ( 'Share Diagnostic Data' ) } < / h2 >
< / header >
< div className = "card__content" >
< FormField
type = "checkbox"
name = "share_usage_data"
onChange = { this . onShareDataChange }
checked = { daemonSettings . share _usage _data }
postfix = { _ _ (
'Help make LBRY better by contributing analytics and diagnostic data about my usage.'
) }
helper = { _ _ (
'You will be ineligible to earn rewards while diagnostics are not being shared.'
) }
/ >
< / div >
2018-03-26 23:32:43 +02:00
< / section >
2018-12-19 06:44:53 +01:00
2018-07-18 21:48:30 +02:00
< section className = "card card--section" >
2018-12-19 06:44:53 +01:00
< header className = "card__header" >
< h2 className = "card__title" > { _ _ ( 'Theme' ) } < / h2 >
< / header >
< div className = "card__content" >
2019-01-09 05:29:06 +01:00
< FormRow >
< FormField
name = "theme_select"
type = "select"
onChange = { this . onThemeChange }
value = { currentTheme }
disabled = { automaticDarkModeEnabled }
>
{ themes . map ( theme => (
< option key = { theme } value = { theme } >
{ theme }
< / option >
) ) }
< / FormField >
< / FormRow >
2018-12-19 06:44:53 +01:00
< FormField
type = "checkbox"
name = "automatic_dark_mode"
onChange = { e => this . onAutomaticDarkModeChange ( e . target . checked ) }
checked = { automaticDarkModeEnabled }
disabled = { isDarkModeEnabled }
postfix = { _ _ ( 'Automatic dark mode (9pm to 8am)' ) }
/ >
< / div >
2018-07-18 21:48:30 +02:00
< / section >
2018-12-19 06:44:53 +01:00
2018-07-18 21:48:30 +02:00
< section className = "card card--section" >
2018-12-19 06:44:53 +01:00
< header className = "card__header" >
< h2 className = "card__title" > { _ _ ( 'Wallet Security' ) } < / h2 >
< / header >
< div className = "card__content" >
< FormField
type = "checkbox"
name = "encrypt_wallet"
onChange = { ( ) => this . onChangeEncryptWallet ( ) }
checked = { walletEncrypted }
postfix = { _ _ ( 'Encrypt my wallet with a custom password.' ) }
helper = {
< React.Fragment >
{ _ _ ( 'Secure your local wallet data with a custom password.' ) } { ' ' }
< strong > { _ _ ( 'Lost passwords cannot be recovered.' ) } < / strong >
< Button
button = "link"
label = { _ _ ( 'Learn more' ) }
href = "https://lbry.io/faq/wallet-encryption"
/ >
.
< / React.Fragment >
}
/ >
< / div >
2018-08-29 02:05:14 +02:00
< / section >
2018-12-19 06:44:53 +01:00
2019-01-28 21:05:28 +01:00
< section className = "card card--section" >
< header className = "card__header" >
< h2 className = "card__title" > { _ _ ( 'Experimental Settings' ) } < / h2 >
< / header >
< div className = "card__content" >
< FormRow >
< FormField
type = "checkbox"
name = "auto_download"
onChange = { this . onAutoDownloadChange }
checked = { autoDownload }
postfix = { _ _ ( '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."
) }
/ >
< / FormRow >
< FormRow >
< FormField
type = "checkbox"
name = "autoplay"
onChange = { this . onAutoplayChange }
checked = { autoplay }
postfix = { _ _ ( 'Autoplay media files' ) }
helper = { _ _ (
'Autoplay video and audio files when navigating to a file, as well as the next related item when a file finishes playing.'
) }
/ >
< / FormRow >
< / div >
< / section >
2018-03-26 23:32:43 +02:00
< section className = "card card--section" >
2018-12-19 06:44:53 +01:00
< header className = "card__header" >
< h2 className = "card__title" > { _ _ ( 'Application Cache' ) } < / h2 >
< p className = "card__subtitle" >
{ _ _ ( 'This will clear the application cache. Your wallet will not be affected.' ) }
< / p >
< / header >
2018-03-26 23:32:43 +02:00
< div className = "card__content" >
< Button
button = "primary"
2019-01-09 18:53:05 +01:00
label = { this . state . clearingCache ? _ _ ( 'Clearing' ) : _ _ ( 'Clear Cache' ) }
2018-11-26 02:21:25 +01:00
icon = { ICONS . ALERT }
2018-03-26 23:32:43 +02:00
onClick = { this . clearCache }
disabled = { this . state . clearingCache }
/ >
< / div >
< / section >
< / React.Fragment >
) }
< / Page >
2016-04-10 02:00:56 +02:00
) ;
}
2017-05-17 10:10:25 +02:00
}
2016-11-22 21:19:08 +01:00
export default SettingsPage ;