From a187bc7362e9adf85825fc97376033b1b79a6ce6 Mon Sep 17 00:00:00 2001 From: ezequielnick <107352853+ezequielnick@users.noreply.github.com> Date: Sat, 4 Jan 2025 23:14:32 +0800 Subject: [PATCH] feat: add more core settings --- src/main/core/manager.ts | 26 ++++++++++-- src/renderer/src/locales/en-US.json | 4 ++ src/renderer/src/locales/zh-CN.json | 4 ++ src/renderer/src/pages/mihomo.tsx | 65 +++++++++++++++++++++++++---- src/shared/types.d.ts | 4 ++ 5 files changed, 90 insertions(+), 13 deletions(-) diff --git a/src/main/core/manager.ts b/src/main/core/manager.ts index 267005b..c327153 100644 --- a/src/main/core/manager.ts +++ b/src/main/core/manager.ts @@ -63,7 +63,11 @@ export async function startCore(detached = false): Promise[]> { core = 'mihomo', autoSetDNS = true, diffWorkDir = false, - mihomoCpuPriority = 'PRIORITY_NORMAL' + mihomoCpuPriority = 'PRIORITY_NORMAL', + disableLoopbackDetector = false, + disableEmbedCA = false, + disableSystemCA = false, + skipSafePathCheck = false } = await getAppConfig() const { 'log-level': logLevel } = await getControledMihomoConfig() if (existsSync(path.join(dataDir(), 'core.pid'))) { @@ -93,12 +97,19 @@ export async function startCore(detached = false): Promise[]> { } const stdout = 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( corePath, ['-d', diffWorkDir ? mihomoProfileWorkDir(current) : mihomoWorkDir(), ctlParam, mihomoIpcPath], { detached: detached, - stdio: detached ? 'ignore' : undefined + stdio: detached ? 'ignore' : undefined, + env: env } ) if (process.platform === 'win32' && child.pid) { @@ -212,10 +223,17 @@ export async function quitWithoutCore(): Promise { } async function checkProfile(): Promise { - const { core = 'mihomo', diffWorkDir = false } = await getAppConfig() + const { + core = 'mihomo', + diffWorkDir = false, + skipSafePathCheck = false + } = await getAppConfig() const { current } = await getProfileConfig() const corePath = mihomoCorePath(core) const execFilePromise = promisify(execFile) + const env = { + SKIP_SAFE_PATH_CHECK: String(skipSafePathCheck) + } try { await execFilePromise(corePath, [ '-t', @@ -223,7 +241,7 @@ async function checkProfile(): Promise { diffWorkDir ? mihomoWorkConfigPath(current) : mihomoWorkConfigPath('work'), '-d', mihomoTestDir() - ]) + ], { env }) } catch (error) { if (error instanceof Error && 'stdout' in error) { const { stdout } = error as { stdout: string } diff --git a/src/renderer/src/locales/en-US.json b/src/renderer/src/locales/en-US.json index 131cecf..fa02c02 100644 --- a/src/renderer/src/locales/en-US.json +++ b/src/renderer/src/locales/en-US.json @@ -125,6 +125,10 @@ "mihomo.tcpConcurrent": "TCP Concurrent", "mihomo.storeSelectedNode": "Store Selected Node", "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.logLevel": "Log Level", "mihomo.selectLogLevel": "Select Log Level", diff --git a/src/renderer/src/locales/zh-CN.json b/src/renderer/src/locales/zh-CN.json index 29ef95c..d5cf5f3 100644 --- a/src/renderer/src/locales/zh-CN.json +++ b/src/renderer/src/locales/zh-CN.json @@ -125,6 +125,10 @@ "mihomo.tcpConcurrent": "TCP 并发", "mihomo.storeSelectedNode": "存储选择节点", "mihomo.storeFakeIp": "存储 FakeIP", + "mihomo.disableLoopbackDetector": "禁用回环检测器", + "mihomo.skipSafePathCheck": "禁用安全路径检查", + "mihomo.disableEmbedCA": "不使用内置 CA 证书", + "mihomo.disableSystemCA": "不使用系统 CA 证书", "mihomo.logRetentionDays": "日志保留天数", "mihomo.logLevel": "日志等级", "mihomo.selectLogLevel": "选择日志等级", diff --git a/src/renderer/src/pages/mihomo.tsx b/src/renderer/src/pages/mihomo.tsx index 48d2e54..3435e03 100644 --- a/src/renderer/src/pages/mihomo.tsx +++ b/src/renderer/src/pages/mihomo.tsx @@ -27,7 +27,14 @@ const CoreMap = { const Mihomo: React.FC = () => { const { t } = useTranslation() 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 { ipv6, @@ -70,6 +77,17 @@ const Mihomo: React.FC = () => { 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 ( <> {lanOpen && setLanOpen(false)} />} @@ -119,14 +137,7 @@ const Mihomo: React.FC = () => { aria-label={t('mihomo.selectCoreVersion')} selectedKeys={new Set([core])} onSelectionChange={async (v) => { - try { - await patchAppConfig({ core: v.currentKey as 'mihomo' | 'mihomo-alpha' }) - await restartCore() - } catch (e) { - alert(e) - } finally { - PubSub.publish('mihomo-core-changed') - } + handleConfigChangeWithRestart('core', v.currentKey as 'mihomo' | 'mihomo-alpha') }} > {t(CoreMap['mihomo'])} @@ -637,6 +648,42 @@ const Mihomo: React.FC = () => { }} /> + + { + handleConfigChangeWithRestart('disableLoopbackDetector', v) + }} + /> + + + { + handleConfigChangeWithRestart('skipSafePathCheck', v) + }} + /> + + + { + handleConfigChangeWithRestart('disableEmbedCA', v) + }} + /> + + + { + handleConfigChangeWithRestart('disableSystemCA', v) + }} + /> +