lbry-desktop/src/renderer/page/settings/view.jsx

446 lines
15 KiB
React
Raw Normal View History

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-02-13 17:27:20 +01:00
import { FormField, FormFieldPrice, Form } 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 SetDaemonSettingArg = boolean | string | number | Price;
2018-03-26 23:32:43 +02:00
type DaemonSettings = {
download_dir: string,
2018-03-26 23:32:43 +02:00
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, ?SetDaemonSettingArg) => void,
setClientSetting: (string, SetDaemonSettingArg) => 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,
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,
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);
this.state = {
clearingCache: false,
2017-06-06 23:19:12 +02:00
};
2018-03-26 23:32:43 +02:00
(this: any).onKeyFeeChange = this.onKeyFeeChange.bind(this);
(this: any).onKeyFeeDisableChange = this.onKeyFeeDisableChange.bind(this);
2018-03-26 23:32:43 +02:00
(this: any).onInstantPurchaseMaxChange = this.onInstantPurchaseMaxChange.bind(this);
(this: any).onThemeChange = this.onThemeChange.bind(this);
(this: any).onAutomaticDarkModeChange = this.onAutomaticDarkModeChange.bind(this);
(this: any).clearCache = this.clearCache.bind(this);
}
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
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) {
if (isDisabled) this.setDaemonSetting('max_key_fee');
2017-05-17 10:10:25 +02:00
}
2018-03-26 23:32:43 +02:00
onThemeChange(event: SyntheticInputEvent<*>) {
const { value } = event.target;
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-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);
}
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);
}
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();
}
}
setDaemonSetting(name: string, value: ?SetDaemonSettingArg): void {
2018-10-13 17:49:47 +02:00
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,
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,
osNotificationsEnabled,
autoDownload,
2019-02-13 17:27:20 +01:00
setDaemonSetting,
setClientSetting,
2017-09-07 03:53:42 +02:00
} = this.props;
2018-03-26 23:32:43 +02:00
const noDaemonSettings = !daemonSettings || Object.keys(daemonSettings).length === 0;
const isDarkModeEnabled = currentTheme === 'dark';
const defaultMaxKeyFee = { currency: 'USD', amount: 50 };
const disableMaxKeyFee = !(daemonSettings && daemonSettings.max_key_fee);
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">
<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">
2019-02-13 17:27:20 +01:00
<Form>
<FileSelector
type="openDirectory"
currentPath={daemonSettings.download_dir}
onFileChosen={this.onDownloadDirChange}
/>
</Form>
2018-10-19 22:38:07 +02:00
</div>
2018-03-26 23:32:43 +02:00
</section>
2018-03-26 23:32:43 +02:00
<section className="card card--section">
<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>
2019-02-13 17:27:20 +01:00
<Form className="card__content">
<fieldset-section>
<FormField
type="radio"
name="no_max_purchase_no_limit"
checked={disableMaxKeyFee}
label={__('No Limit')}
onChange={() => {
this.onKeyFeeDisableChange(true);
}}
/>
</fieldset-section>
<fieldset-section>
<FormField
type="radio"
name="max_purchase_limit"
checked={!disableMaxKeyFee}
onChange={() => {
this.onKeyFeeDisableChange(false);
this.onKeyFeeChange(defaultMaxKeyFee);
}}
label={__('Choose limit')}
/>
</fieldset-section>
{!disableMaxKeyFee && (
2018-04-11 00:05:30 +02:00
<FormFieldPrice
name="max_key_fee"
min={0}
onChange={this.onKeyFeeChange}
price={
daemonSettings.max_key_fee ? daemonSettings.max_key_fee : defaultMaxKeyFee
2018-04-11 00:05:30 +02:00
}
/>
)}
2019-02-13 17:27:20 +01:00
</Form>
2018-03-26 23:32:43 +02:00
</section>
2018-03-26 23:32:43 +02:00
<section className="card card--section">
<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>
2019-02-13 17:27:20 +01:00
<Form className="card__content">
<fieldset-section>
<FormField
type="radio"
name="confirm_all_purchases"
checked={!instantPurchaseEnabled}
label={__('Always confirm before purchasing content')}
onChange={() => {
this.onInstantPurchaseEnabledChange(false);
}}
/>
</fieldset-section>
<fieldset-section>
<FormField
type="radio"
name="instant_purchases"
checked={instantPurchaseEnabled}
label={__('Only confirm purchases over a certain price')}
onChange={() => {
this.onInstantPurchaseEnabledChange(true);
}}
/>
</fieldset-section>
2018-04-11 00:05:30 +02:00
{instantPurchaseEnabled && (
<FormFieldPrice
2019-02-13 17:27:20 +01:00
name="confirmation_price"
2018-04-11 00:05:30 +02:00
min={0.1}
onChange={this.onInstantPurchaseMaxChange}
price={instantPurchaseMax}
/>
)}
2019-02-13 17:27:20 +01:00
</Form>
2018-03-26 23:32:43 +02:00
</section>
2018-03-26 23:32:43 +02:00
<section className="card card--section">
<header className="card__header">
<h2 className="card__title">{__('Content Settings')}</h2>
</header>
2019-02-13 17:27:20 +01:00
<Form className="card__content">
<FormField
type="setting"
name="show_nsfw"
onChange={() => setClientSetting(SETTINGS.SHOW_NSFW, !showNsfw)}
checked={showNsfw}
label={__('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. '
)}
/>
</Form>
2018-03-26 23:32:43 +02:00
</section>
<section className="card card--section">
<header className="card__header">
<h2 className="card__title">{__('Notifications')}</h2>
</header>
2019-02-13 17:27:20 +01:00
<Form className="card__content">
<FormField
2019-02-13 17:27:20 +01:00
type="setting"
name="desktopNotification"
2019-02-13 17:27:20 +01:00
onChange={() =>
setClientSetting(SETTINGS.OS_NOTIFICATIONS_ENABLED, !osNotificationsEnabled)
}
checked={osNotificationsEnabled}
2019-02-13 17:27:20 +01:00
label={__('Show Desktop Notifications')}
helper={__(
'Get notified when a publish is confirmed, or when new content is available to watch.'
)}
/>
2019-02-13 17:27:20 +01:00
</Form>
</section>
2018-03-26 23:32:43 +02:00
<section className="card card--section">
<header className="card__header">
<h2 className="card__title">{__('Share Diagnostic Data')}</h2>
</header>
2019-02-13 17:27:20 +01:00
<Form className="card__content">
<FormField
2019-02-13 17:27:20 +01:00
type="setting"
name="share_usage_data"
2019-02-13 17:27:20 +01:00
onChange={() =>
setDaemonSetting('share_usage_data', !daemonSettings.share_usage_data)
}
checked={daemonSettings.share_usage_data}
2019-02-13 17:27:20 +01:00
label={__(
'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.'
)}
/>
2019-02-13 17:27:20 +01:00
</Form>
2018-03-26 23:32:43 +02:00
</section>
2018-07-18 21:48:30 +02:00
<section className="card card--section">
<header className="card__header">
2019-02-13 17:27:20 +01:00
<h2 className="card__title">{__('Appearance')}</h2>
</header>
2019-02-13 17:27:20 +01:00
<Form className="card__content">
<fieldset-section>
2019-01-09 05:29:06 +01:00
<FormField
name="theme_select"
type="select"
2019-02-13 17:27:20 +01:00
label={__('Theme')}
2019-01-09 05:29:06 +01:00
onChange={this.onThemeChange}
value={currentTheme}
disabled={automaticDarkModeEnabled}
>
{themes.map(theme => (
<option key={theme} value={theme}>
{theme}
</option>
))}
</FormField>
2019-02-13 17:27:20 +01:00
</fieldset-section>
<fieldset-section>
<FormField
type="setting"
name="automatic_dark_mode"
onChange={() => this.onAutomaticDarkModeChange(!automaticDarkModeEnabled)}
checked={automaticDarkModeEnabled}
disabled={isDarkModeEnabled}
label={__('Automatic dark mode (9pm to 8am)')}
/>
</fieldset-section>
</Form>
2018-07-18 21:48:30 +02:00
</section>
2018-07-18 21:48:30 +02:00
<section className="card card--section">
<header className="card__header">
<h2 className="card__title">{__('Wallet Security')}</h2>
</header>
2019-02-13 17:27:20 +01:00
<Form className="card__content">
<FormField
2019-02-13 17:27:20 +01:00
type="setting"
name="encrypt_wallet"
onChange={() => this.onChangeEncryptWallet()}
checked={walletEncrypted}
2019-02-13 17:27:20 +01:00
label={__('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>
}
/>
2019-02-13 17:27:20 +01:00
</Form>
2018-08-29 02:05:14 +02:00
</section>
<section className="card card--section">
<header className="card__header">
<h2 className="card__title">{__('Experimental Settings')}</h2>
</header>
2019-02-13 17:27:20 +01:00
<Form className="card__content">
<FormField
type="setting"
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."
)}
/>
<FormField
type="setting"
name="autoplay"
onChange={() => setClientSetting(SETTINGS.AUTOPLAY, !autoplay)}
checked={autoplay}
label={__('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.'
)}
/>
</Form>
</section>
2018-03-26 23:32:43 +02:00
<section className="card card--section">
<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}
2019-02-13 17:27:20 +01:00
// onClick={this.clearCache}
2018-03-26 23:32:43 +02:00
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;