[System] grab Network & Data Settings

This commit is contained in:
infinite-persistence 2021-08-06 16:25:37 +08:00
parent a40257f551
commit 7d34233e54
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
4 changed files with 70 additions and 47 deletions

View file

@ -1,10 +1,15 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { doClearCache } from 'redux/actions/app'; import { doClearCache } from 'redux/actions/app';
import { doSetDaemonSetting } from 'redux/actions/settings';
import { selectDaemonSettings } from 'redux/selectors/settings';
import SettingSystem from './view'; import SettingSystem from './view';
const select = (state) => ({}); const select = (state) => ({
daemonSettings: selectDaemonSettings(state),
});
const perform = (dispatch) => ({ const perform = (dispatch) => ({
setDaemonSetting: (key, value) => dispatch(doSetDaemonSetting(key, value)),
clearCache: () => dispatch(doClearCache()), clearCache: () => dispatch(doClearCache()),
}); });

View file

@ -3,6 +3,7 @@ import { ALERT } from 'constants/icons';
import React from 'react'; import React from 'react';
import Button from 'component/button'; import Button from 'component/button';
import Card from 'component/common/card'; import Card from 'component/common/card';
import { FormField } from 'component/common/form';
import SettingAutoLaunch from 'component/settingAutoLaunch'; import SettingAutoLaunch from 'component/settingAutoLaunch';
import SettingClosingBehavior from 'component/settingClosingBehavior'; import SettingClosingBehavior from 'component/settingClosingBehavior';
import SettingsRow from 'component/settingsRow'; import SettingsRow from 'component/settingsRow';
@ -11,12 +12,31 @@ import SettingsRow from 'component/settingsRow';
const IS_MAC = process.platform === 'darwin'; const IS_MAC = process.platform === 'darwin';
// @endif // @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 = { type Props = {
daemonSettings: DaemonSettings,
setDaemonSetting: (string, ?SetDaemonSettingArg) => void,
clearCache: () => Promise<any>, clearCache: () => Promise<any>,
}; };
export default function SettingSystem(props: Props) { export default function SettingSystem(props: Props) {
const { clearCache } = props; const { daemonSettings, setDaemonSetting, clearCache } = props;
const [clearingCache, setClearingCache] = React.useState(false); const [clearingCache, setClearingCache] = React.useState(false);
return ( return (
@ -26,10 +46,47 @@ export default function SettingSystem(props: Props) {
isBodyList isBodyList
body={ body={
<> <>
{/* @if TARGET='app' */}
<SettingsRow
title={__('Save all viewed content to your downloads directory')}
subtitle={__(
'Paid content and some file types are saved by default. Changing this setting will not affect previously downloaded content.'
)}
>
<FormField
type="checkbox"
name="save_files"
onChange={() => setDaemonSetting('save_files', !daemonSettings.save_files)}
checked={daemonSettings.save_files}
/>
</SettingsRow>
<SettingsRow
title={__('Save hosting data to help the LBRY network')}
subtitle={
<React.Fragment>
{__("If disabled, LBRY will be very sad and you won't be helping improve the network.")}{' '}
<Button button="link" label={__('Learn more')} href="https://lbry.com/faq/host-content" />.
</React.Fragment>
}
>
<FormField
type="checkbox"
name="save_blobs"
onChange={() => setDaemonSetting('save_blobs', !daemonSettings.save_blobs)}
checked={daemonSettings.save_blobs}
/>
</SettingsRow>
{/* @endif */}
{/* @if TARGET='app' */} {/* @if TARGET='app' */}
{/* Auto launch in a hidden state doesn't work on mac https://github.com/Teamwork/node-auto-launch/issues/81 */} {/* Auto launch in a hidden state doesn't work on mac https://github.com/Teamwork/node-auto-launch/issues/81 */}
{!IS_MAC && ( {!IS_MAC && (
<SettingsRow title={__('Start minimized')} subtitle={__(HELP_START_MINIMIZED)}> <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 /> <SettingAutoLaunch noLabels />
</SettingsRow> </SettingsRow>
)} )}
@ -41,7 +98,10 @@ export default function SettingSystem(props: Props) {
</SettingsRow> </SettingsRow>
{/* @endif */} {/* @endif */}
<SettingsRow title={__('Clear application cache')} subtitle={__(HELP_CLEAR_CACHE)}> <SettingsRow
title={__('Clear application cache')}
subtitle={__('This might fix issues that you are having. Your wallet will not be affected.')}
>
<Button <Button
button="secondary" button="secondary"
icon={ALERT} icon={ALERT}
@ -58,7 +118,3 @@ export default function SettingSystem(props: Props) {
/> />
); );
} }
const HELP_START_MINIMIZED =
'Improve view speed and help the LBRY network by allowing the app to cuddle up in your system tray.';
const HELP_CLEAR_CACHE = 'This might fix issues that you are having. Your wallet will not be affected.';

View file

@ -2,7 +2,6 @@ import { connect } from 'react-redux';
import { doClearCache, doNotifyEncryptWallet, doNotifyDecryptWallet, doNotifyForgetPassword } from 'redux/actions/app'; import { doClearCache, doNotifyEncryptWallet, doNotifyDecryptWallet, doNotifyForgetPassword } from 'redux/actions/app';
import { selectAllowAnalytics } from 'redux/selectors/app'; import { selectAllowAnalytics } from 'redux/selectors/app';
import { import {
doSetDaemonSetting,
doClearDaemonSetting, doClearDaemonSetting,
doSetClientSetting, doSetClientSetting,
doFindFFmpeg, doFindFFmpeg,
@ -33,7 +32,6 @@ const select = (state) => ({
}); });
const perform = (dispatch) => ({ const perform = (dispatch) => ({
setDaemonSetting: (key, value) => dispatch(doSetDaemonSetting(key, value)),
clearDaemonSetting: (key) => dispatch(doClearDaemonSetting(key)), clearDaemonSetting: (key) => dispatch(doClearDaemonSetting(key)),
clearCache: () => dispatch(doClearCache()), clearCache: () => dispatch(doClearCache()),
setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)), setClientSetting: (key, value) => dispatch(doSetClientSetting(key, value)),

View file

@ -31,7 +31,6 @@ type DaemonSettings = {
}; };
type Props = { type Props = {
setDaemonSetting: (string, ?SetDaemonSettingArg) => void,
clearDaemonSetting: (string) => void, clearDaemonSetting: (string) => void,
setClientSetting: (string, SetDaemonSettingArg) => void, setClientSetting: (string, SetDaemonSettingArg) => void,
daemonSettings: DaemonSettings, daemonSettings: DaemonSettings,
@ -154,7 +153,7 @@ class SettingsAdvancedPage extends React.PureComponent<Props, State> {
} }
setDaemonSetting(name: string, value: ?SetDaemonSettingArg): void { setDaemonSetting(name: string, value: ?SetDaemonSettingArg): void {
this.props.setDaemonSetting(name, value); // this.props.setDaemonSetting(name, value);
} }
clearDaemonSetting(name: string): void { clearDaemonSetting(name: string): void {
@ -173,7 +172,6 @@ class SettingsAdvancedPage extends React.PureComponent<Props, State> {
instantPurchaseMax, instantPurchaseMax,
isAuthenticated, isAuthenticated,
walletEncrypted, walletEncrypted,
setDaemonSetting,
setClientSetting, setClientSetting,
hideBalance, hideBalance,
findingFFmpeg, findingFFmpeg,
@ -202,40 +200,6 @@ class SettingsAdvancedPage extends React.PureComponent<Props, State> {
</section> </section>
) : ( ) : (
<div> <div>
{/* @if TARGET='app' */}
<Card
title={__('Network and data settings')}
actions={
<React.Fragment>
<FormField
type="checkbox"
name="save_files"
onChange={() => setDaemonSetting('save_files', !daemonSettings.save_files)}
checked={daemonSettings.save_files}
label={__('Save all viewed content to your downloads directory')}
helper={__(
'Paid content and some file types are saved by default. Changing this setting will not affect previously downloaded content.'
)}
/>
<FormField
type="checkbox"
name="save_blobs"
onChange={() => setDaemonSetting('save_blobs', !daemonSettings.save_blobs)}
checked={daemonSettings.save_blobs}
label={__('Save hosting data to help the LBRY network')}
helper={
<React.Fragment>
{__("If disabled, LBRY will be very sad and you won't be helping improve the network.")}{' '}
<Button button="link" label={__('Learn more')} href="https://lbry.com/faq/host-content" />.
</React.Fragment>
}
/>
</React.Fragment>
}
/>
{/* @endif */}
<Card <Card
title={__('Purchase and tip confirmations')} title={__('Purchase and tip confirmations')}
actions={ actions={