add more mihomo config

This commit is contained in:
pompurin404 2024-08-18 18:21:40 +08:00
parent 71aedc1b70
commit 82edf850b8
No known key found for this signature in database
4 changed files with 60 additions and 22 deletions

View File

@ -1,7 +1,7 @@
### New Features ### New Features
- 支持应用内自动更新 - 支持设置是否存储选择节点
### Bug Fixes ### Bug Fixes
- 修复某些Mac设备无法开启虚拟网卡的问题 - 修复单例检测与一键导入冲突的问题

View File

@ -40,6 +40,7 @@ export const defaultControledMihomoConfig: Partial<IMihomoConfig> = {
'tproxy-port': 0, 'tproxy-port': 0,
'allow-lan': false, 'allow-lan': false,
'unified-delay': false, 'unified-delay': false,
'tcp-concurrent': false,
'log-level': 'info', 'log-level': 'info',
'find-process-mode': 'strict', 'find-process-mode': 'strict',
tun: { tun: {
@ -82,6 +83,10 @@ export const defaultControledMihomoConfig: Partial<IMihomoConfig> = {
}, },
'skip-domain': ['+.push.apple.com'] 'skip-domain': ['+.push.apple.com']
}, },
profile: {
'store-selected': true,
'store-fake-ip': true
},
'geo-auto-update': false, 'geo-auto-update': false,
'geo-update-interval': 24, 'geo-update-interval': 24,
'geodata-mode': false, 'geodata-mode': false,

View File

@ -5,7 +5,7 @@ import SettingItem from '@renderer/components/base/base-setting-item'
import { useAppConfig } from '@renderer/hooks/use-app-config' import { useAppConfig } from '@renderer/hooks/use-app-config'
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config' import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
import { platform } from '@renderer/utils/init' import { platform } from '@renderer/utils/init'
import { patchMihomoConfig, restartCore } from '@renderer/utils/ipc' import { restartCore } from '@renderer/utils/ipc'
import React, { useState } from 'react' import React, { useState } from 'react'
const CoreMap = { const CoreMap = {
@ -21,16 +21,19 @@ const Mihomo: React.FC = () => {
ipv6, ipv6,
'external-controller': externalController, 'external-controller': externalController,
secret, secret,
'log-level': level = 'info', 'log-level': logLevel = 'info',
'find-process-mode': mode = 'strict', 'find-process-mode': findProcessMode = 'strict',
'allow-lan': lan, 'allow-lan': allowLan,
'unified-delay': delay, 'unified-delay': unifiedDelay,
'tcp-concurrent': tcpConcurrent,
'mixed-port': mixedPort = 7890, 'mixed-port': mixedPort = 7890,
'socks-port': socksPort = 7891, 'socks-port': socksPort = 7891,
port: httpPort = 7892, port: httpPort = 7892,
'redir-port': redirPort = 0, 'redir-port': redirPort = 0,
'tproxy-port': tproxyPort = 0 'tproxy-port': tproxyPort = 0,
profile = {}
} = controledMihomoConfig || {} } = controledMihomoConfig || {}
const { 'store-selected': storeSelected, 'store-fake-ip': storeFakeIp } = profile
const [mixedPortInput, setMixedPortInput] = useState(mixedPort) const [mixedPortInput, setMixedPortInput] = useState(mixedPort)
const [socksPortInput, setSocksPortInput] = useState(socksPort) const [socksPortInput, setSocksPortInput] = useState(socksPort)
@ -40,11 +43,6 @@ const Mihomo: React.FC = () => {
const [externalControllerInput, setExternalControllerInput] = useState(externalController) const [externalControllerInput, setExternalControllerInput] = useState(externalController)
const [secretInput, setSecretInput] = useState(secret) const [secretInput, setSecretInput] = useState(secret)
const onChange = async (patch: Partial<IMihomoConfig>): Promise<void> => {
await patchControledMihomoConfig(patch)
await patchMihomoConfig(patch)
}
const onChangeNeedRestart = async (patch: Partial<IMihomoConfig>): Promise<void> => { const onChangeNeedRestart = async (patch: Partial<IMihomoConfig>): Promise<void> => {
await patchControledMihomoConfig(patch) await patchControledMihomoConfig(patch)
await restartCore() await restartCore()
@ -271,25 +269,52 @@ const Mihomo: React.FC = () => {
size="sm" size="sm"
isSelected={ipv6} isSelected={ipv6}
onValueChange={(v) => { onValueChange={(v) => {
onChange({ ipv6: v }) onChangeNeedRestart({ ipv6: v })
}} }}
/> />
</SettingItem> </SettingItem>
<SettingItem title="允许局域网连接" divider> <SettingItem title="允许局域网连接" divider>
<Switch <Switch
size="sm" size="sm"
isSelected={lan} isSelected={allowLan}
onValueChange={(v) => { onValueChange={(v) => {
onChange({ 'allow-lan': v }) onChangeNeedRestart({ 'allow-lan': v })
}} }}
/> />
</SettingItem> </SettingItem>
<SettingItem title="使用RTT延迟测试" divider> <SettingItem title="使用RTT延迟测试" divider>
<Switch <Switch
size="sm" size="sm"
isSelected={delay} isSelected={unifiedDelay}
onValueChange={(v) => { onValueChange={(v) => {
onChange({ 'unified-delay': v }) onChangeNeedRestart({ 'unified-delay': v })
}}
/>
</SettingItem>
<SettingItem title="TCP并发" divider>
<Switch
size="sm"
isSelected={tcpConcurrent}
onValueChange={(v) => {
onChangeNeedRestart({ 'tcp-concurrent': v })
}}
/>
</SettingItem>
<SettingItem title="存储选择节点" divider>
<Switch
size="sm"
isSelected={storeSelected}
onValueChange={(v) => {
onChangeNeedRestart({ profile: { 'store-selected': v } })
}}
/>
</SettingItem>
<SettingItem title="存储FakeIP" divider>
<Switch
size="sm"
isSelected={storeFakeIp}
onValueChange={(v) => {
onChangeNeedRestart({ profile: { 'store-fake-ip': v } })
}} }}
/> />
</SettingItem> </SettingItem>
@ -297,9 +322,9 @@ const Mihomo: React.FC = () => {
<Select <Select
className="w-[100px]" className="w-[100px]"
size="sm" size="sm"
selectedKeys={new Set([level])} selectedKeys={new Set([logLevel])}
onSelectionChange={(v) => { onSelectionChange={(v) => {
onChange({ 'log-level': v.currentKey as LogLevel }) onChangeNeedRestart({ 'log-level': v.currentKey as LogLevel })
}} }}
> >
<SelectItem key="silent"></SelectItem> <SelectItem key="silent"></SelectItem>
@ -313,9 +338,9 @@ const Mihomo: React.FC = () => {
<Select <Select
className="w-[100px]" className="w-[100px]"
size="sm" size="sm"
selectedKeys={new Set([mode])} selectedKeys={new Set([findProcessMode])}
onSelectionChange={(v) => { onSelectionChange={(v) => {
onChange({ 'find-process-mode': v.currentKey as FindProcessMode }) onChangeNeedRestart({ 'find-process-mode': v.currentKey as FindProcessMode })
}} }}
> >
<SelectItem key="strict"></SelectItem> <SelectItem key="strict"></SelectItem>

View File

@ -296,6 +296,12 @@ interface IMihomoSnifferConfig {
} }
} }
} }
interface IMihomoProfileConfig {
'store-selected'?: boolean
'store-fake-ip'?: boolean
}
interface IMihomoConfig { interface IMihomoConfig {
'external-controller': string 'external-controller': string
secret?: string secret?: string
@ -304,6 +310,7 @@ interface IMihomoConfig {
'mixed-port': number 'mixed-port': number
'allow-lan': boolean 'allow-lan': boolean
'unified-delay': boolean 'unified-delay': boolean
'tcp-concurrent': boolean
'log-level': LogLevel 'log-level': LogLevel
'find-process-mode': FindProcessMode 'find-process-mode': FindProcessMode
'socks-port'?: number 'socks-port'?: number
@ -326,6 +333,7 @@ interface IMihomoConfig {
tun: IMihomoTunConfig tun: IMihomoTunConfig
dns: IMihomoDNSConfig dns: IMihomoDNSConfig
sniffer: IMihomoSnifferConfig sniffer: IMihomoSnifferConfig
profile: IMihomoProfileConfig
} }
interface IProfileConfig { interface IProfileConfig {