Skip to content

Commit 2514ea3

Browse files
pompurin404pompurin404
pompurin404
authored and
pompurin404
committed
adjust styles
1 parent 41f709d commit 2514ea3

File tree

6 files changed

+93
-78
lines changed

6 files changed

+93
-78
lines changed

src/main/resolve/init.ts

-30
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import {
22
appConfigPath,
33
controledMihomoConfigPath,
44
dataDir,
5-
exePath,
65
logDir,
7-
mihomoCorePath,
86
mihomoTestDir,
97
mihomoWorkDir,
108
profileConfigPath,
@@ -25,7 +23,6 @@ import { startPacServer } from './server'
2523
import { triggerSysProxy } from './sysproxy'
2624
import { getAppConfig } from '../config'
2725
import { app } from 'electron'
28-
import { execSync } from 'child_process'
2926

3027
function initDirs(): void {
3128
if (!fs.existsSync(dataDir)) {
@@ -85,38 +82,11 @@ function initDeeplink(): void {
8582
}
8683
}
8784

88-
function initFirewall(): void {
89-
const removeCommand = `
90-
Remove-NetFirewallRule -DisplayName "mihomo" -ErrorAction SilentlyContinue
91-
Remove-NetFirewallRule -DisplayName "mihomo-alpha" -ErrorAction SilentlyContinue
92-
Remove-NetFirewallRule -DisplayName "Mihomo Party" -ErrorAction SilentlyContinue
93-
`
94-
const createCommand = `
95-
New-NetFirewallRule -DisplayName "mihomo" -Direction Inbound -Action Allow -Program "${mihomoCorePath('mihomo')}" -Enabled True -Profile Any -ErrorAction SilentlyContinue
96-
New-NetFirewallRule -DisplayName "mihomo-alpha" -Direction Inbound -Action Allow -Program "${mihomoCorePath('mihomo-alpha')}" -Enabled True -Profile Any -ErrorAction SilentlyContinue
97-
New-NetFirewallRule -DisplayName "Mihomo Party" -Direction Inbound -Action Allow -Program "${exePath()}" -Enabled True -Profile Any -ErrorAction SilentlyContinue
98-
`
99-
100-
if (process.platform === 'win32') {
101-
try {
102-
execSync(removeCommand, { shell: 'powershell' })
103-
} catch {
104-
console.log('Remove-NetFirewallRule Failed')
105-
}
106-
try {
107-
execSync(createCommand, { shell: 'powershell' })
108-
} catch {
109-
console.log('New-NetFirewallRule Failed')
110-
}
111-
}
112-
}
113-
11485
export function init(): void {
11586
initDirs()
11687
initConfig()
11788
initFiles()
11889
initDeeplink()
119-
initFirewall()
12090
startPacServer().then(() => {
12191
triggerSysProxy(getAppConfig().sysProxy.enable)
12292
})

src/main/utils/ipc.ts

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { app, ipcMain, safeStorage } from 'electron'
1+
import { app, dialog, ipcMain, safeStorage } from 'electron'
22
import {
33
mihomoChangeProxy,
44
mihomoCloseAllConnections,
@@ -33,6 +33,8 @@ import {
3333
import { isEncryptionAvailable, startCore } from '../core/manager'
3434
import { triggerSysProxy } from '../resolve/sysproxy'
3535
import { checkUpdate } from '../resolve/autoUpdater'
36+
import { exePath, mihomoCorePath } from './dirs'
37+
import { execSync } from 'child_process'
3638

3739
export function registerIpcMainHandlers(): void {
3840
ipcMain.handle('mihomoVersion', mihomoVersion)
@@ -71,5 +73,37 @@ export function registerIpcMainHandlers(): void {
7173
ipcMain.handle('checkUpdate', () => checkUpdate())
7274
ipcMain.handle('getVersion', () => app.getVersion())
7375
ipcMain.handle('platform', () => process.platform)
76+
ipcMain.handle('setupFirewall', setupFirewall)
7477
ipcMain.handle('quitApp', () => app.quit())
7578
}
79+
80+
async function setupFirewall(): Promise<void> {
81+
return new Promise((resolve, reject) => {
82+
const removeCommand = `
83+
Remove-NetFirewallRule -DisplayName "mihomo" -ErrorAction SilentlyContinue
84+
Remove-NetFirewallRule -DisplayName "mihomo-alpha" -ErrorAction SilentlyContinue
85+
Remove-NetFirewallRule -DisplayName "Mihomo Party" -ErrorAction SilentlyContinue
86+
`
87+
const createCommand = `
88+
New-NetFirewallRule -DisplayName "mihomo" -Direction Inbound -Action Allow -Program "${mihomoCorePath('mihomo')}" -Enabled True -Profile Any -ErrorAction SilentlyContinue
89+
New-NetFirewallRule -DisplayName "mihomo-alpha" -Direction Inbound -Action Allow -Program "${mihomoCorePath('mihomo-alpha')}" -Enabled True -Profile Any -ErrorAction SilentlyContinue
90+
New-NetFirewallRule -DisplayName "Mihomo Party" -Direction Inbound -Action Allow -Program "${exePath()}" -Enabled True -Profile Any -ErrorAction SilentlyContinue
91+
`
92+
93+
if (process.platform === 'win32') {
94+
try {
95+
execSync(removeCommand, { shell: 'powershell' })
96+
} catch {
97+
console.log('Remove-NetFirewallRule Failed')
98+
}
99+
try {
100+
execSync(createCommand, { shell: 'powershell' })
101+
} catch (e) {
102+
dialog.showErrorBox('防火墙设置失败', `${e}`)
103+
reject(e)
104+
console.log('New-NetFirewallRule Failed')
105+
}
106+
}
107+
resolve()
108+
})
109+
}
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,29 @@
1-
import { Button, Divider } from '@nextui-org/react'
2-
import { FaChevronRight } from 'react-icons/fa'
1+
import { Divider } from '@nextui-org/react'
2+
33
import React from 'react'
44

55
interface Props {
6-
onPress?: () => void
76
title: React.ReactNode
87
actions?: React.ReactNode
98
children?: React.ReactNode
109
divider?: boolean
1110
}
1211

1312
const SettingItem: React.FC<Props> = (props) => {
14-
const { title, actions, children, divider = false, onPress } = props
15-
if (onPress) {
16-
return (
17-
<>
18-
<div className="p-0 m-0 h-[32px] w-full flex justify-between">
13+
const { title, actions, children, divider = false } = props
14+
15+
return (
16+
<>
17+
<div className="h-[32px] w-full flex justify-between">
18+
<div className="h-full flex items-center">
1919
<h4 className="h-full select-none text-md leading-[32px]">{title}</h4>
20-
<Button size="sm" onPress={onPress}>
21-
<FaChevronRight />
22-
</Button>
23-
</div>
24-
{divider && <Divider className="my-2" />}
25-
</>
26-
)
27-
} else {
28-
return (
29-
<>
30-
<div className="h-[32px] w-full flex justify-between">
31-
<div className="h-full flex items-center">
32-
<h4 className="h-full select-none text-md leading-[32px]">{title}</h4>
33-
<div>{actions}</div>
34-
</div>
35-
{children}
20+
<div>{actions}</div>
3621
</div>
37-
{divider && <Divider className="my-2" />}
38-
</>
39-
)
40-
}
22+
{children}
23+
</div>
24+
{divider && <Divider className="my-2" />}
25+
</>
26+
)
4127
}
4228

4329
export default SettingItem

src/renderer/src/pages/settings.tsx

+24-17
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,30 @@ const Settings: React.FC = () => {
9898
</SettingItem>
9999
</SettingCard>
100100
<SettingCard>
101-
<SettingItem
102-
title="检查更新"
103-
divider
104-
onPress={() => {
105-
checkUpdate().then((v) => {
106-
if (v) {
107-
new window.Notification(`v${v}版本已发布`, { body: '点击前往下载' }).onclick =
108-
(): void => {
109-
open(`https://github.com/pompurin404/mihomo-party/releases/tag/v${v}`)
110-
}
111-
} else {
112-
new window.Notification('当前已是最新版本', { body: '无需更新' })
113-
}
114-
})
115-
}}
116-
/>
117-
<SettingItem title="退出应用" onPress={quitApp} divider />
101+
<SettingItem title="检查更新" divider>
102+
<Button
103+
size="sm"
104+
onPress={() => {
105+
checkUpdate().then((v) => {
106+
if (v) {
107+
new window.Notification(`v${v}版本已发布`, { body: '点击前往下载' }).onclick =
108+
(): void => {
109+
open(`https://github.com/pompurin404/mihomo-party/releases/tag/v${v}`)
110+
}
111+
} else {
112+
new window.Notification('当前已是最新版本', { body: '无需更新' })
113+
}
114+
})
115+
}}
116+
>
117+
检查更新
118+
</Button>
119+
</SettingItem>
120+
<SettingItem title="退出应用" divider>
121+
<Button size="sm" onPress={quitApp}>
122+
退出应用
123+
</Button>
124+
</SettingItem>
118125
<SettingItem title="应用版本">
119126
<div className="select-none">v{version}</div>
120127
</SettingItem>

src/renderer/src/pages/tun.tsx

+16-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ import BasePage from '@renderer/components/base/base-page'
33
import SettingCard from '@renderer/components/base/base-setting-card'
44
import SettingItem from '@renderer/components/base/base-setting-item'
55
import { useControledMihomoConfig } from '@renderer/hooks/use-controled-mihomo-config'
6-
import { restartCore } from '@renderer/utils/ipc'
6+
import { restartCore, setupFirewall } from '@renderer/utils/ipc'
77
import { platform } from '@renderer/utils/init'
88
import React, { Key, useState } from 'react'
99

1010
const Tun: React.FC = () => {
1111
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
1212
const { tun } = controledMihomoConfig || {}
13+
const [loading, setLoading] = useState(false)
1314
const {
1415
device = 'Mihomo',
1516
stack = 'mixed',
@@ -134,7 +135,7 @@ const Tun: React.FC = () => {
134135
}}
135136
/>
136137
</SettingItem>
137-
<SettingItem title="DNS 劫持">
138+
<SettingItem title="DNS 劫持" divider>
138139
<Input
139140
size="sm"
140141
className="w-[50%]"
@@ -144,6 +145,19 @@ const Tun: React.FC = () => {
144145
}}
145146
/>
146147
</SettingItem>
148+
<SettingItem title="重设防火墙">
149+
<Button
150+
size="sm"
151+
color="primary"
152+
isLoading={loading}
153+
onPress={() => {
154+
setLoading(true)
155+
setupFirewall().finally(() => setLoading(false))
156+
}}
157+
>
158+
重设防火墙
159+
</Button>
160+
</SettingItem>
147161
</SettingCard>
148162
</BasePage>
149163
)

src/renderer/src/utils/ipc.ts

+4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ export async function getPlatform(): Promise<NodeJS.Platform> {
143143
return await window.electron.ipcRenderer.invoke('platform')
144144
}
145145

146+
export async function setupFirewall(): Promise<void> {
147+
return await window.electron.ipcRenderer.invoke('setupFirewall')
148+
}
149+
146150
export async function quitApp(): Promise<void> {
147151
return await window.electron.ipcRenderer.invoke('quitApp')
148152
}

0 commit comments

Comments
 (0)