From c0ff201efb58765bc108b3c97efdc8d635f26921 Mon Sep 17 00:00:00 2001 From: yaling888 <73897884+yaling888@users.noreply.github.com> Date: Mon, 16 May 2022 03:14:22 +0800 Subject: feat: add "update geo databases" & "tls sniffing switch" to config page --- src/api/configs.ts | 9 ++++++++ src/components/Config.tsx | 52 +++++++++++++++++++++++++++++++---------------- src/i18n/en.ts | 3 +++ src/i18n/zh.ts | 3 +++ src/store/configs.ts | 39 ++++++++++++++++++++++++++--------- src/store/types.ts | 1 + 6 files changed, 80 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/api/configs.ts b/src/api/configs.ts index ed2b1e9..3734958 100644 --- a/src/api/configs.ts +++ b/src/api/configs.ts @@ -3,6 +3,7 @@ import { ClashGeneralConfig, TunPartial } from 'src/store/types'; import { ClashAPIConfig } from 'src/types'; const endpoint = '/configs'; +const updateGeoDatabasesFileEndpoint = '/configs/geo'; const flushFakeIPPoolEndpoint = '/cache/fakeip/flush'; export async function fetchConfigs(apiConfig: ClashAPIConfig) { @@ -40,6 +41,14 @@ export async function reloadConfigFile( return await fetch(url + endpoint + '?force=true', { ...init, body, method: 'PUT' }); } +export async function updateGeoDatabasesFile( + apiConfig: ClashAPIConfig +) { + const { url, init } = getURLAndInit(apiConfig); + const body = '{"path": "", "payload": ""}'; + return await fetch(url + updateGeoDatabasesFileEndpoint, { ...init, body, method: 'POST' }); +} + export async function flushFakeIPPool( apiConfig: ClashAPIConfig ) { diff --git a/src/components/Config.tsx b/src/components/Config.tsx index 7d0bcd3..a8438c1 100644 --- a/src/components/Config.tsx +++ b/src/components/Config.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { LogOut, RotateCw, Trash2 } from 'react-feather'; +import { DownloadCloud, LogOut, RotateCw, Trash2 } from 'react-feather'; import { useTranslation } from 'react-i18next'; import * as logsApi from 'src/api/logs'; import Select from 'src/components/shared/Select'; @@ -17,6 +17,7 @@ import { getConfigs, reloadConfigFile, updateConfigs, + updateGeoDatabasesFile, } from '../store/configs'; import { openModal } from '../store/modals'; import Button from './Button'; @@ -46,7 +47,6 @@ 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: 'mitm-port', label: 'MITM Port' }, ]; @@ -131,21 +131,13 @@ function ConfigImpl({ [configState] ); - const handleSwitchOnChange = useCallback( - (checked: boolean) => { - const name = 'allow-lan'; - const value = checked; - setConfigState(name, value); - dispatch(updateConfigs(apiConfig, { 'allow-lan': value })); - }, - [apiConfig, dispatch, setConfigState] - ); - const handleChangeValue = useCallback( ({ name, value }) => { switch (name) { case 'mode': case 'log-level': + case 'allow-lan': + case 'sniffing': setConfigState(name, value); dispatch(updateConfigs(apiConfig, { [name]: value })); if (name === 'log-level') { @@ -153,7 +145,6 @@ function ConfigImpl({ } break; case 'mitm-port': - case 'tproxy-port': case 'redir-port': case 'socks-port': case 'mixed-port': @@ -167,7 +158,7 @@ function ConfigImpl({ case 'enable': case 'stack': setTunConfigState(name, value); - dispatch(updateConfigs(apiConfig, { 'tun': {[name]: value }})); + dispatch(updateConfigs(apiConfig, { 'tun': { [name]: value }})); break; default: return; @@ -192,7 +183,6 @@ function ConfigImpl({ case 'socks-port': case 'mixed-port': case 'redir-port': - case 'tproxy-port': case 'mitm-port': { const num = parseInt(value, 10); if (num < 0 || num > 65535) return; @@ -214,6 +204,10 @@ function ConfigImpl({ dispatch(reloadConfigFile(apiConfig)); },[apiConfig, dispatch]); + const handleUpdateGeoDatabasesFile = useCallback(() => { + dispatch(updateGeoDatabasesFile(apiConfig)); + },[apiConfig, dispatch]); + const handleFlushFakeIPPool = useCallback(() => { dispatch(flushFakeIPPool(apiConfig)); },[apiConfig, dispatch]); @@ -262,12 +256,27 @@ function ConfigImpl({
-
Allow LAN
+
{t('allow_lan')}
+ handleChangeValue({ name: 'allow-lan', value: value }) + } + /> +
+
+ +
+
{t('tls_sniffing')}
+
+ + handleChangeValue({ name: 'sniffing', value: value }) + } />
@@ -316,6 +325,15 @@ function ConfigImpl({ /> +
+
GEO Databases
+
+
FakeIP