feat: add more core settings

This commit is contained in:
ezequielnick 2025-01-04 23:14:32 +08:00
parent 9d84c6ac9b
commit a187bc7362
5 changed files with 90 additions and 13 deletions

View File

@ -63,7 +63,11 @@ export async function startCore(detached = false): Promise<Promise<void>[]> {
core = 'mihomo', core = 'mihomo',
autoSetDNS = true, autoSetDNS = true,
diffWorkDir = false, diffWorkDir = false,
mihomoCpuPriority = 'PRIORITY_NORMAL' mihomoCpuPriority = 'PRIORITY_NORMAL',
disableLoopbackDetector = false,
disableEmbedCA = false,
disableSystemCA = false,
skipSafePathCheck = false
} = await getAppConfig() } = await getAppConfig()
const { 'log-level': logLevel } = await getControledMihomoConfig() const { 'log-level': logLevel } = await getControledMihomoConfig()
if (existsSync(path.join(dataDir(), 'core.pid'))) { if (existsSync(path.join(dataDir(), 'core.pid'))) {
@ -93,12 +97,19 @@ export async function startCore(detached = false): Promise<Promise<void>[]> {
} }
const stdout = createWriteStream(logPath(), { flags: 'a' }) const stdout = createWriteStream(logPath(), { flags: 'a' })
const stderr = createWriteStream(logPath(), { flags: 'a' }) const stderr = createWriteStream(logPath(), { flags: 'a' })
const env = {
DISABLE_LOOPBACK_DETECTOR: String(disableLoopbackDetector),
DISABLE_EMBED_CA: String(disableEmbedCA),
DISABLE_SYSTEM_CA: String(disableSystemCA),
SKIP_SAFE_PATH_CHECK: String(skipSafePathCheck)
}
child = spawn( child = spawn(
corePath, corePath,
['-d', diffWorkDir ? mihomoProfileWorkDir(current) : mihomoWorkDir(), ctlParam, mihomoIpcPath], ['-d', diffWorkDir ? mihomoProfileWorkDir(current) : mihomoWorkDir(), ctlParam, mihomoIpcPath],
{ {
detached: detached, detached: detached,
stdio: detached ? 'ignore' : undefined stdio: detached ? 'ignore' : undefined,
env: env
} }
) )
if (process.platform === 'win32' && child.pid) { if (process.platform === 'win32' && child.pid) {
@ -212,10 +223,17 @@ export async function quitWithoutCore(): Promise<void> {
} }
async function checkProfile(): Promise<void> { async function checkProfile(): Promise<void> {
const { core = 'mihomo', diffWorkDir = false } = await getAppConfig() const {
core = 'mihomo',
diffWorkDir = false,
skipSafePathCheck = false
} = await getAppConfig()
const { current } = await getProfileConfig() const { current } = await getProfileConfig()
const corePath = mihomoCorePath(core) const corePath = mihomoCorePath(core)
const execFilePromise = promisify(execFile) const execFilePromise = promisify(execFile)
const env = {
SKIP_SAFE_PATH_CHECK: String(skipSafePathCheck)
}
try { try {
await execFilePromise(corePath, [ await execFilePromise(corePath, [
'-t', '-t',
@ -223,7 +241,7 @@ async function checkProfile(): Promise<void> {
diffWorkDir ? mihomoWorkConfigPath(current) : mihomoWorkConfigPath('work'), diffWorkDir ? mihomoWorkConfigPath(current) : mihomoWorkConfigPath('work'),
'-d', '-d',
mihomoTestDir() mihomoTestDir()
]) ], { env })
} catch (error) { } catch (error) {
if (error instanceof Error && 'stdout' in error) { if (error instanceof Error && 'stdout' in error) {
const { stdout } = error as { stdout: string } const { stdout } = error as { stdout: string }

View File

@ -125,6 +125,10 @@
"mihomo.tcpConcurrent": "TCP Concurrent", "mihomo.tcpConcurrent": "TCP Concurrent",
"mihomo.storeSelectedNode": "Store Selected Node", "mihomo.storeSelectedNode": "Store Selected Node",
"mihomo.storeFakeIp": "Store Fake IP", "mihomo.storeFakeIp": "Store Fake IP",
"mihomo.disableLoopbackDetector": "Disable Loopback Detector",
"mihomo.skipSafePathCheck": "Skip Safe Path Check",
"mihomo.disableEmbedCA": "Disable Embed CA",
"mihomo.disableSystemCA": "Disable System CA",
"mihomo.logRetentionDays": "Log Retention Days", "mihomo.logRetentionDays": "Log Retention Days",
"mihomo.logLevel": "Log Level", "mihomo.logLevel": "Log Level",
"mihomo.selectLogLevel": "Select Log Level", "mihomo.selectLogLevel": "Select Log Level",

View File

@ -125,6 +125,10 @@
"mihomo.tcpConcurrent": "TCP 并发", "mihomo.tcpConcurrent": "TCP 并发",
"mihomo.storeSelectedNode": "存储选择节点", "mihomo.storeSelectedNode": "存储选择节点",
"mihomo.storeFakeIp": "存储 FakeIP", "mihomo.storeFakeIp": "存储 FakeIP",
"mihomo.disableLoopbackDetector": "禁用回环检测器",
"mihomo.skipSafePathCheck": "禁用安全路径检查",
"mihomo.disableEmbedCA": "不使用内置 CA 证书",
"mihomo.disableSystemCA": "不使用系统 CA 证书",
"mihomo.logRetentionDays": "日志保留天数", "mihomo.logRetentionDays": "日志保留天数",
"mihomo.logLevel": "日志等级", "mihomo.logLevel": "日志等级",
"mihomo.selectLogLevel": "选择日志等级", "mihomo.selectLogLevel": "选择日志等级",

View File

@ -27,7 +27,14 @@ const CoreMap = {
const Mihomo: React.FC = () => { const Mihomo: React.FC = () => {
const { t } = useTranslation() const { t } = useTranslation()
const { appConfig, patchAppConfig } = useAppConfig() const { appConfig, patchAppConfig } = useAppConfig()
const { core = 'mihomo', maxLogDays = 7, sysProxy } = appConfig || {} const {
core = 'mihomo',
maxLogDays = 7,
sysProxy,
disableLoopbackDetector,
disableEmbedCA,
disableSystemCA,
skipSafePathCheck } = appConfig || {}
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig() const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
const { const {
ipv6, ipv6,
@ -70,6 +77,17 @@ const Mihomo: React.FC = () => {
await restartCore() await restartCore()
} }
const handleConfigChangeWithRestart = async (key: string, value: any) => {
try {
await patchAppConfig({ [key]: value })
await restartCore()
} catch (e) {
alert(e)
} finally {
PubSub.publish('mihomo-core-changed')
}
}
return ( return (
<> <>
{lanOpen && <InterfaceModal onClose={() => setLanOpen(false)} />} {lanOpen && <InterfaceModal onClose={() => setLanOpen(false)} />}
@ -119,14 +137,7 @@ const Mihomo: React.FC = () => {
aria-label={t('mihomo.selectCoreVersion')} aria-label={t('mihomo.selectCoreVersion')}
selectedKeys={new Set([core])} selectedKeys={new Set([core])}
onSelectionChange={async (v) => { onSelectionChange={async (v) => {
try { handleConfigChangeWithRestart('core', v.currentKey as 'mihomo' | 'mihomo-alpha')
await patchAppConfig({ core: v.currentKey as 'mihomo' | 'mihomo-alpha' })
await restartCore()
} catch (e) {
alert(e)
} finally {
PubSub.publish('mihomo-core-changed')
}
}} }}
> >
<SelectItem key="mihomo">{t(CoreMap['mihomo'])}</SelectItem> <SelectItem key="mihomo">{t(CoreMap['mihomo'])}</SelectItem>
@ -637,6 +648,42 @@ const Mihomo: React.FC = () => {
}} }}
/> />
</SettingItem> </SettingItem>
<SettingItem title={t('mihomo.disableLoopbackDetector')} divider>
<Switch
size="sm"
isSelected={disableLoopbackDetector}
onValueChange={(v) => {
handleConfigChangeWithRestart('disableLoopbackDetector', v)
}}
/>
</SettingItem>
<SettingItem title={t('mihomo.skipSafePathCheck')} divider>
<Switch
size="sm"
isSelected={skipSafePathCheck}
onValueChange={(v) => {
handleConfigChangeWithRestart('skipSafePathCheck', v)
}}
/>
</SettingItem>
<SettingItem title={t('mihomo.disableEmbedCA')} divider>
<Switch
size="sm"
isSelected={disableEmbedCA}
onValueChange={(v) => {
handleConfigChangeWithRestart('disableEmbedCA', v)
}}
/>
</SettingItem>
<SettingItem title={t('mihomo.disableSystemCA')} divider>
<Switch
size="sm"
isSelected={disableSystemCA}
onValueChange={(v) => {
handleConfigChangeWithRestart('disableSystemCA', v)
}}
/>
</SettingItem>
<SettingItem title={t('mihomo.logRetentionDays')} divider> <SettingItem title={t('mihomo.logRetentionDays')} divider>
<Input <Input
size="sm" size="sm"

View File

@ -217,6 +217,10 @@ interface ISysProxyConfig {
interface IAppConfig { interface IAppConfig {
core: 'mihomo' | 'mihomo-alpha' core: 'mihomo' | 'mihomo-alpha'
disableLoopbackDetector: boolean
disableEmbedCA: boolean
disableSystemCA: boolean
skipSafePathCheck: boolean
proxyDisplayMode: 'simple' | 'full' proxyDisplayMode: 'simple' | 'full'
proxyDisplayOrder: 'default' | 'delay' | 'name' proxyDisplayOrder: 'default' | 'delay' | 'name'
profileDisplayDate?: 'expire' | 'update' profileDisplayDate?: 'expire' | 'update'