diff --git a/src/main/utils/template.ts b/src/main/utils/template.ts index e3438b7..cb7db1c 100644 --- a/src/main/utils/template.ts +++ b/src/main/utils/template.ts @@ -44,7 +44,17 @@ export const defaultConfig: IAppConfig = { ], siderWidth: 250, sysProxy: { enable: false, mode: 'manual' }, - triggerMainWindowBehavior: 'show' // 添加默认值 + triggerMainWindowBehavior: 'show', + showMixedPort: 7890, + enableMixedPort: true, + showSocksPort: 7891, + enableSocksPort: true, + showHttpPort: 7892, + enableHttpPort: true, + showRedirPort: 0, + enableRedirPort: false, + showTproxyPort: 0, + enableTproxyPort: false } export const defaultControledMihomoConfig: Partial = { diff --git a/src/renderer/src/pages/mihomo.tsx b/src/renderer/src/pages/mihomo.tsx index 7060cb5..a620f9c 100644 --- a/src/renderer/src/pages/mihomo.tsx +++ b/src/renderer/src/pages/mihomo.tsx @@ -6,7 +6,7 @@ import { useAppConfig } from '@renderer/hooks/use-app-config' import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config' import { platform } from '@renderer/utils/init' import { FaNetworkWired } from 'react-icons/fa' -import { IoMdCloudDownload, IoMdInformationCircleOutline, IoMdRefresh } from 'react-icons/io' +import { IoMdCloudDownload, IoMdInformationCircleOutline, IoMdRefresh, IoMdShuffle } from 'react-icons/io' import PubSub from 'pubsub-js' import { mihomoUpgrade, @@ -42,7 +42,21 @@ const Mihomo: React.FC = () => { smartCoreCollectData = false, smartCoreStrategy = 'sticky-sessions', maxLogDays = 7, - sysProxy + sysProxy, + disableLoopbackDetector, + disableEmbedCA, + disableSystemCA, + skipSafePathCheck, + showMixedPort, + enableMixedPort = true, + showSocksPort, + enableSocksPort = true, + showHttpPort, + enableHttpPort = true, + showRedirPort, + enableRedirPort = false, + showTproxyPort, + enableTproxyPort = false } = appConfig || {} const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig() @@ -75,11 +89,12 @@ const Mihomo: React.FC = () => { } = controledMihomoConfig || {} const { 'store-selected': storeSelected, 'store-fake-ip': storeFakeIp } = profile - const [mixedPortInput, setMixedPortInput] = useState(mixedPort) - const [socksPortInput, setSocksPortInput] = useState(socksPort) - const [httpPortInput, setHttpPortInput] = useState(httpPort) - const [redirPortInput, setRedirPortInput] = useState(redirPort) - const [tproxyPortInput, setTproxyPortInput] = useState(tproxyPort) + const [isManualPortChange, setIsManualPortChange] = useState(false) + const [mixedPortInput, setMixedPortInput] = useState(showMixedPort || mixedPort) + const [socksPortInput, setSocksPortInput] = useState(showSocksPort || socksPort) + const [httpPortInput, setHttpPortInput] = useState(showHttpPort || httpPort) + const [redirPortInput, setRedirPortInput] = useState(showRedirPort || redirPort) + const [tproxyPortInput, setTproxyPortInput] = useState(showTproxyPort || tproxyPort) const [externalControllerInput, setExternalControllerInput] = useState(externalController) const [secretInput, setSecretInput] = useState(secret) const [lanAllowedIpsInput, setLanAllowedIpsInput] = useState(lanAllowedIps) @@ -116,6 +131,9 @@ const Mihomo: React.FC = () => { const { host, port } = parseController() + // 生成随机端口(范围1024-65535) + const generateRandomPort = () => Math.floor(Math.random() * (65535 - 1024 + 1)) + 1024 + // 默认WebUI面板选项 const defaultWebUIPanels: WebUIPanel[] = [ { @@ -613,7 +631,7 @@ const Mihomo: React.FC = () => {
- {mixedPortInput !== mixedPort && ( + {isManualPortChange && mixedPortInput !== mixedPort && ( + { + patchAppConfig({ enableMixedPort: value }) + if (value) { + const port = appConfig?.showMixedPort + onChangeNeedRestart({ 'mixed-port': port }) + } else { + onChangeNeedRestart({ 'mixed-port': 0 }) + } }} />
- {socksPortInput !== socksPort && ( + {isManualPortChange && socksPortInput !== socksPort && ( + { + patchAppConfig({ enableSocksPort: value }) + if (value) { + const port = appConfig?.showSocksPort || socksPort + onChangeNeedRestart({ 'socks-port': port }) + } else { + onChangeNeedRestart({ 'socks-port': 0 }) + } }} />
- {httpPortInput !== httpPort && ( + {isManualPortChange && httpPortInput !== httpPort && ( + { + patchAppConfig({ enableHttpPort: value }) + if (value) { + const port = appConfig?.showHttpPort || httpPort + onChangeNeedRestart({ port: port }) + } else { + onChangeNeedRestart({ port: 0 }) + } }} />
@@ -702,13 +811,13 @@ const Mihomo: React.FC = () => { {platform !== 'win32' && (
- {redirPortInput !== redirPort && ( + {isManualPortChange && redirPortInput !== redirPort && ( + { + patchAppConfig({ enableRedirPort: value }) + if (value) { + const port = appConfig?.showRedirPort || redirPort + onChangeNeedRestart({ 'redir-port': port }) + } else { + onChangeNeedRestart({ 'redir-port': 0 }) + } }} />
@@ -732,13 +872,13 @@ const Mihomo: React.FC = () => { {platform === 'linux' && (
- {tproxyPortInput !== tproxyPort && ( + {isManualPortChange && tproxyPortInput !== tproxyPort && ( + { + patchAppConfig({ enableTproxyPort: value }) + if (value) { + const port = appConfig?.showTproxyPort || tproxyPort + onChangeNeedRestart({ 'tproxy-port': port }) + } else { + onChangeNeedRestart({ 'tproxy-port': 0 }) + } }} />
diff --git a/src/shared/types.d.ts b/src/shared/types.d.ts index 1a1a5ae..d190012 100644 --- a/src/shared/types.d.ts +++ b/src/shared/types.d.ts @@ -312,6 +312,16 @@ interface IAppConfig { quitWithoutCoreShortcut?: string language?: 'zh-CN' | 'en-US' | 'ru-RU' | 'fa-IR' triggerMainWindowBehavior?: 'show' | 'toggle' + showMixedPort?: number + enableMixedPort?: boolean + showSocksPort?: number + enableSocksPort?: boolean + showHttpPort?: number + enableHttpPort?: boolean + showRedirPort?: number + enableRedirPort?: boolean + showTproxyPort?: number + enableTproxyPort?: boolean } interface IMihomoTunConfig {