Skip to content

Commit 14d7335

Browse files
author
pompurin404
committed
control all port
1 parent a7a8578 commit 14d7335

File tree

3 files changed

+133
-1
lines changed

3 files changed

+133
-1
lines changed

src/main/utils/template.ts

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ export const defaultControledMihomoConfig: Partial<IMihomoConfig> = {
1212
ipv6: false,
1313
mode: 'rule',
1414
'mixed-port': 7890,
15+
'socks-port': 7891,
16+
port: 7892,
17+
'redir-port': 0,
18+
'tproxy-port': 0,
1519
'allow-lan': false,
1620
'unified-delay': false,
1721
'log-level': 'info',

src/renderer/src/pages/mihomo.tsx

+127-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import SettingCard from '@renderer/components/base/base-setting-card'
44
import SettingItem from '@renderer/components/base/base-setting-item'
55
import { useAppConfig } from '@renderer/hooks/use-app-config'
66
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
7+
import { platform } from '@renderer/utils/init'
78
import { patchMihomoConfig, restartCore } from '@renderer/utils/ipc'
89
import React, { useState } from 'react'
910

@@ -24,10 +25,18 @@ const Mihomo: React.FC = () => {
2425
'find-process-mode': mode = 'strict',
2526
'allow-lan': lan,
2627
'unified-delay': delay,
27-
'mixed-port': mixedPort = 7890
28+
'mixed-port': mixedPort = 7890,
29+
'socks-port': socksPort = 7891,
30+
port: httpPort = 7892,
31+
'redir-port': redirPort = 0,
32+
'tproxy-port': tproxyPort = 0
2833
} = controledMihomoConfig || {}
2934

3035
const [mixedPortInput, setMixedPortInput] = useState(mixedPort)
36+
const [socksPortInput, setSocksPortInput] = useState(socksPort)
37+
const [httpPortInput, setHttpPortInput] = useState(httpPort)
38+
const [redirPortInput, setRedirPortInput] = useState(redirPort)
39+
const [tproxyPortInput, setTproxyPortInput] = useState(tproxyPort)
3140
const [externalControllerInput, setExternalControllerInput] = useState(externalController)
3241
const [secretInput, setSecretInput] = useState(secret)
3342

@@ -86,6 +95,122 @@ const Mihomo: React.FC = () => {
8695
/>
8796
</div>
8897
</SettingItem>
98+
<SettingItem title="Socks端口" divider>
99+
<div className="flex">
100+
{socksPortInput !== socksPort && (
101+
<Button
102+
size="sm"
103+
color="primary"
104+
className="mr-2"
105+
onPress={() => {
106+
onChangeNeedRestart({ 'socks-port': socksPortInput })
107+
}}
108+
>
109+
确认
110+
</Button>
111+
)}
112+
113+
<Input
114+
size="sm"
115+
type="number"
116+
className="w-[100px]"
117+
value={socksPortInput.toString()}
118+
max={65535}
119+
min={0}
120+
onValueChange={(v) => {
121+
setSocksPortInput(parseInt(v))
122+
}}
123+
/>
124+
</div>
125+
</SettingItem>
126+
<SettingItem title="Http端口" divider>
127+
<div className="flex">
128+
{httpPortInput !== httpPort && (
129+
<Button
130+
size="sm"
131+
color="primary"
132+
className="mr-2"
133+
onPress={() => {
134+
onChangeNeedRestart({ port: httpPortInput })
135+
}}
136+
>
137+
确认
138+
</Button>
139+
)}
140+
141+
<Input
142+
size="sm"
143+
type="number"
144+
className="w-[100px]"
145+
value={httpPortInput.toString()}
146+
max={65535}
147+
min={0}
148+
onValueChange={(v) => {
149+
setHttpPortInput(parseInt(v))
150+
}}
151+
/>
152+
</div>
153+
</SettingItem>
154+
{platform !== 'win32' && (
155+
<SettingItem title="Redir端口" divider>
156+
<div className="flex">
157+
{redirPortInput !== redirPort && (
158+
<Button
159+
size="sm"
160+
color="primary"
161+
className="mr-2"
162+
onPress={() => {
163+
onChangeNeedRestart({ 'redir-port': redirPortInput })
164+
}}
165+
>
166+
确认
167+
</Button>
168+
)}
169+
170+
<Input
171+
size="sm"
172+
type="number"
173+
className="w-[100px]"
174+
value={redirPortInput.toString()}
175+
max={65535}
176+
min={0}
177+
onValueChange={(v) => {
178+
setRedirPortInput(parseInt(v))
179+
}}
180+
/>
181+
</div>
182+
</SettingItem>
183+
)}
184+
{platform === 'linux' && (
185+
<SettingItem title="TProxy端口" divider>
186+
<div className="flex">
187+
{tproxyPortInput !== tproxyPort && (
188+
<Button
189+
size="sm"
190+
color="primary"
191+
className="mr-2"
192+
onPress={() => {
193+
onChangeNeedRestart({ 'tproxy-port': tproxyPortInput })
194+
}}
195+
>
196+
确认
197+
</Button>
198+
)}
199+
200+
<Input
201+
size="sm"
202+
type="number"
203+
className="w-[100px]"
204+
value={tproxyPortInput.toString()}
205+
max={65535}
206+
min={0}
207+
onValueChange={(v) => {
208+
setTproxyPortInput(parseInt(v))
209+
}}
210+
/>
211+
</div>
212+
</SettingItem>
213+
)}
89214
<SettingItem title="外部控制" divider>
90215
<div className="flex">
91216
{externalControllerInput !== externalController && (
@@ -127,6 +252,7 @@ const Mihomo: React.FC = () => {
127252

128253
<Input
129254
size="sm"
255+
type="password"
130256
value={secretInput}
131257
onValueChange={(v) => {
132258
setSecretInput(v)

src/shared/types.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ interface IMihomoConfig {
185185
'log-level': LogLevel
186186
'find-process-mode': FindProcessMode
187187
'socks-port'?: number
188+
'redir-port'?: number
189+
'tproxy-port'?: number
188190
port?: number
189191
proxies?: []
190192
'proxy-groups'?: []

0 commit comments

Comments
 (0)