From e5a6393fa8cdf4c92b2e68b5d2f4c7633ca5d690 Mon Sep 17 00:00:00 2001 From: yaling888 <73897884+yaling888@users.noreply.github.com> Date: Sat, 7 May 2022 02:43:42 +0800 Subject: feat: add tun stack config to config page --- src/components/Config.tsx | 100 +++++++++++++++++++++++++++++++--------------- 1 file changed, 67 insertions(+), 33 deletions(-) (limited to 'src/components') diff --git a/src/components/Config.tsx b/src/components/Config.tsx index 3d9e36e..808ffd9 100644 --- a/src/components/Config.tsx +++ b/src/components/Config.tsx @@ -11,7 +11,13 @@ import { getLatencyTestUrl, getSelectedChartStyleIndex, } from '../store/app'; -import { fetchConfigs, getConfigs, updateConfigs, reloadConfigs, flushFakeIPPool } from '../store/configs'; +import { + fetchConfigs, + flushFakeIPPool, + getConfigs, + reloadConfigFile, + updateConfigs, +} from '../store/configs'; import { openModal } from '../store/modals'; import Button from './Button'; import s0 from './Config.module.scss'; @@ -40,7 +46,7 @@ const portFields = [ { key: 'socks-port', label: 'SOCKS5 Proxy Port' }, { key: 'mixed-port', label: 'Mixed Port' }, { key: 'redir-port', label: 'Redir Port' }, - { key: 'tproxy-port', label: 'tProxy Port' }, + { key: 'tproxy-port', label: 'TProxy Port' }, { key: 'mitm-port', label: 'MITM Port' }, ]; @@ -50,10 +56,15 @@ const langOptions = [ ]; const modeOptions = [ - ['Global', 'Global'], - ['Rule', 'Rule'], - ['Script', 'Script'], - ['Direct', 'Direct'], + ['rule', 'Rule'], + ['script', 'Script'], + ['direct', 'Direct'], + ['global', 'Global'], +]; + +const tunStackOptions = [ + ['gVisor', 'gVisor'], + ['System', 'System'], ]; const mapState = (s: State) => ({ @@ -112,6 +123,14 @@ function ConfigImpl({ [configState] ); + const setTunConfigState = useCallback( + (name, val) => { + const tun = {...configState.tun, [name]: val } + setConfigStateInternal({ ...configState, tun: {...tun}}); + }, + [configState] + ); + const handleSwitchOnChange = useCallback( (checked: boolean) => { const name = 'allow-lan'; @@ -145,11 +164,15 @@ function ConfigImpl({ } setConfigState(name, value); break; + case 'stack': + setTunConfigState(name, value); + dispatch(updateConfigs(apiConfig, { 'tun': {[name]: value }})); + break; default: return; } }, - [apiConfig, dispatch, setConfigState] + [apiConfig, dispatch, setConfigState, setTunConfigState] ); const handleInputOnChange = useCallback( @@ -186,8 +209,8 @@ function ConfigImpl({ [apiConfig, dispatch, updateAppConfig] ); - const handleReloadConfigs = useCallback(() => { - dispatch(reloadConfigs(apiConfig)); + const handleReloadConfigFile = useCallback(() => { + dispatch(reloadConfigFile(apiConfig)); },[apiConfig, dispatch]); const handleFlushFakeIPPool = useCallback(() => { @@ -242,6 +265,17 @@ function ConfigImpl({ /> +