/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @format */ import React, {Component, useContext} from 'react'; import {Radio} from 'antd'; import {updateSettings, Action} from '../reducers/settings'; import { Action as LauncherAction, updateLauncherSettings, } from '../reducers/launcherSettings'; import {connect} from 'react-redux'; import {State as Store} from '../reducers'; import {flush} from '../utils/persistor'; import ToggledSection from './settings/ToggledSection'; import {FilePathConfigField, ConfigText} from './settings/configFields'; import KeyboardShortcutInput from './settings/KeyboardShortcutInput'; import {isEqual, isMatch, isEmpty} from 'lodash'; import LauncherSettingsPanel from '../fb-stubs/LauncherSettingsPanel'; import { LauncherSettings, Platform, reportUsage, Settings, } from 'flipper-common'; import {Modal, message, Button} from 'antd'; import {Layout, withTrackingScope, _NuxManagerContext} from 'flipper-plugin'; import {getRenderHostInstance} from '../RenderHost'; import {loadTheme} from '../utils/loadTheme'; type OwnProps = { onHide: () => void; platform: Platform; noModal?: boolean; // used for testing }; type StateFromProps = { settings: Settings; launcherSettings: LauncherSettings; }; type DispatchFromProps = { updateSettings: (settings: Settings) => Action; updateLauncherSettings: (settings: LauncherSettings) => LauncherAction; }; type State = { updatedSettings: Settings; updatedLauncherSettings: LauncherSettings; forcedRestartSettings: Partial; forcedRestartLauncherSettings: Partial; }; type Props = OwnProps & StateFromProps & DispatchFromProps; class SettingsSheet extends Component { state: State = { updatedSettings: {...this.props.settings}, updatedLauncherSettings: {...this.props.launcherSettings}, forcedRestartSettings: {}, forcedRestartLauncherSettings: {}, }; componentDidMount() { reportUsage('settings:opened'); } applyChanges = async () => { this.props.updateSettings(this.state.updatedSettings); this.props.updateLauncherSettings(this.state.updatedLauncherSettings); this.props.onHide(); return flush().then(() => { getRenderHostInstance().restartFlipper(true); }); }; applyChangesWithoutRestart = async () => { this.props.updateSettings(this.state.updatedSettings); this.props.updateLauncherSettings(this.state.updatedLauncherSettings); await flush(); this.props.onHide(); }; renderSandyContainer( contents: React.ReactElement, footer: React.ReactElement, ) { return ( {contents} ); } render() { const { enableAndroid, androidHome, enableIOS, enablePhysicalIOS, enablePrefetching, idbPath, reactNative, darkMode, suppressPluginErrors, } = this.state.updatedSettings; const settingsPristine = isEqual(this.props.settings, this.state.updatedSettings) && isEqual(this.props.launcherSettings, this.state.updatedLauncherSettings); const forcedRestart = (!isEmpty(this.state.forcedRestartSettings) && !isMatch(this.props.settings, this.state.forcedRestartSettings)) || (!isEmpty(this.state.forcedRestartLauncherSettings) && !isMatch( this.props.launcherSettings, this.state.forcedRestartLauncherSettings, )); const contents = ( { this.setState({ updatedSettings: { ...this.state.updatedSettings, enableAndroid: v, }, }); }}> { this.setState({ updatedSettings: { ...this.state.updatedSettings, androidHome: v, }, }); }} /> { this.setState({ updatedSettings: {...this.state.updatedSettings, enableIOS: v}, }); }}> {' '} {this.props.platform === 'darwin' && ( )} {this.props.platform !== 'darwin' && ( )} { this.setState({ updatedSettings: { ...this.state.updatedSettings, enablePhysicalIOS: v, }, }); }}> { this.setState({ updatedSettings: {...this.state.updatedSettings, idbPath: v}, }); }} /> { this.setState({ updatedSettings: { ...this.state.updatedSettings, enablePrefetching: v, }, }); }} isLocalPinIgnored={this.state.updatedLauncherSettings.ignoreLocalPin} onIgnoreLocalPinChange={(v) => { this.setState({ updatedLauncherSettings: { ...this.state.updatedLauncherSettings, ignoreLocalPin: v, }, }); }} releaseChannel={this.state.updatedLauncherSettings.releaseChannel} onReleaseChannelChange={(v) => { this.setState({ updatedLauncherSettings: { ...this.state.updatedLauncherSettings, releaseChannel: v, }, forcedRestartLauncherSettings: { ...this.state.forcedRestartLauncherSettings, releaseChannel: v, }, }); }} /> { this.setState((prevState) => ({ updatedSettings: { ...prevState.updatedSettings, suppressPluginErrors: enabled, }, })); }} /> Theme Selection { this.setState((prevState) => ({ updatedSettings: { ...prevState.updatedSettings, darkMode: event.target.value, }, })); loadTheme(event.target.value); }}> Dark Light Use System Setting { this.setState((prevState) => ({ updatedSettings: { ...prevState.updatedSettings, reactNative: { ...prevState.updatedSettings.reactNative, shortcuts: { ...prevState.updatedSettings.reactNative.shortcuts, enabled, }, }, }, })); }}> { this.setState((prevState) => ({ updatedSettings: { ...prevState.updatedSettings, reactNative: { ...prevState.updatedSettings.reactNative, shortcuts: { ...prevState.updatedSettings.reactNative.shortcuts, reload, }, }, }, })); }} /> { this.setState((prevState) => ({ updatedSettings: { ...prevState.updatedSettings, reactNative: { ...prevState.updatedSettings.reactNative, shortcuts: { ...prevState.updatedSettings.reactNative.shortcuts, openDevMenu, }, }, }, })); }} /> Reset all new user tooltips Reset all local storage based state ); const footer = ( <> ); return this.props.noModal ? ( <> {contents} {footer} ) : ( this.renderSandyContainer(contents, footer) ); } } export default connect( ({settingsState, launcherSettingsState}) => ({ settings: settingsState, launcherSettings: launcherSettingsState, }), {updateSettings, updateLauncherSettings}, )(withTrackingScope(SettingsSheet)); function ResetTooltips() { const nuxManager = useContext(_NuxManagerContext); return ( ); } function ResetLocalState() { return ( ); }