diff options
| author | yaling888 <[email protected]> | 2022-05-07 02:43:42 +0800 |
|---|---|---|
| committer | yaling888 <[email protected]> | 2022-05-07 02:43:42 +0800 |
| commit | e5a6393fa8cdf4c92b2e68b5d2f4c7633ca5d690 (patch) | |
| tree | 24e08847d6f3f7f615e2e8ef45282e39bf2f348d /src/store | |
| parent | aff98308f361b26e419e2b4b80c2ae0b800d19de (diff) | |
feat: add tun stack config to config page
Diffstat (limited to 'src/store')
| -rw-r--r-- | src/store/configs.ts | 28 | ||||
| -rw-r--r-- | src/store/types.ts | 16 |
2 files changed, 39 insertions, 5 deletions
diff --git a/src/store/configs.ts b/src/store/configs.ts index b0ae2a7..c4b95de 100644 --- a/src/store/configs.ts +++ b/src/store/configs.ts @@ -4,6 +4,7 @@ import { GetStateFn, State, StateConfigs, + TunPartial, } from 'src/store/types'; import { ClashAPIConfig } from 'src/types'; @@ -59,9 +60,11 @@ function markHaveFetchedConfig() { }; } +type generalConfig = Omit<ClashGeneralConfig, 'tun'> + export function updateConfigs( apiConfig: ClashAPIConfig, - partialConfg: Partial<ClashGeneralConfig> + partialConfg: TunPartial<ClashGeneralConfig> ) { return async (dispatch: DispatchFn) => { configsAPI @@ -84,15 +87,20 @@ export function updateConfigs( }); dispatch('storeConfigsOptimisticUpdateConfigs', (s) => { - s.configs.configs = { ...s.configs.configs, ...partialConfg }; + if (partialConfg.tun != null) { + s.configs.configs.tun = { ...s.configs.configs.tun, ...partialConfg.tun }; + } else { + const config: generalConfig = {...s.configs.configs, ...partialConfg}; + s.configs.configs = config + } }); }; } -export function reloadConfigs(apiConfig: ClashAPIConfig) { +export function reloadConfigFile(apiConfig: ClashAPIConfig) { return async (dispatch: DispatchFn) => { configsAPI - .reloadConfigs(apiConfig) + .reloadConfigFile(apiConfig) .then( (res) => { if (res.ok === false) { @@ -139,10 +147,20 @@ export const initialState: StateConfigs = { configs: { port: 7890, 'socks-port': 7891, + 'mixed-port': 0, 'redir-port': 0, + 'tproxy-port': 0, + 'mitm-port': 0, 'allow-lan': false, - mode: 'Rule', + mode: 'rule', 'log-level': 'uninit', + tun: { + enable: false, + device: '', + stack: '', + 'dns-hijack': [], + 'auto-route': false, + }, }, haveFetchedConfig: false, }; diff --git a/src/store/types.ts b/src/store/types.ts index b9141ac..16402ae 100644 --- a/src/store/types.ts +++ b/src/store/types.ts @@ -16,15 +16,31 @@ export type StateApp = { logStreamingPaused: boolean; }; +export type ClashTunConfig = { + enable: boolean; + device?: string; + stack: string; + 'dns-hijack': string[]; + 'auto-route': boolean; +} + export type ClashGeneralConfig = { port: number; 'socks-port': number; + 'mixed-port': number; 'redir-port': number; + 'tproxy-port': number; + 'mitm-port'?: number; 'allow-lan': boolean; mode: string; 'log-level': string; + tun?: ClashTunConfig; }; +export type TunPartial<T> = { + [P in keyof T]?: T[P] extends ClashTunConfig ? TunPartial<T[P]> : T[P]; +} + ///// store.proxies type LatencyHistory = Array<{ time: string; delay: number }>; |
