mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/mihomo-party-org/clash-party.git
synced 2026-09-20 08:03:39 +08:00
fix: use netsh to manage firewall rules for Windows 7 compatibility
This commit is contained in:
@@ -58,23 +58,22 @@ export async function openUWPTool(): Promise<void> {
|
||||
|
||||
export async function setupFirewall(): Promise<void> {
|
||||
const execPromise = promisify(exec)
|
||||
const removeCommand = `
|
||||
$rules = @("mihomo", "mihomo-alpha", "Mihomo Party")
|
||||
foreach ($rule in $rules) {
|
||||
if (Get-NetFirewallRule -DisplayName $rule -ErrorAction SilentlyContinue) {
|
||||
Remove-NetFirewallRule -DisplayName $rule -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
`
|
||||
const createCommand = `
|
||||
New-NetFirewallRule -DisplayName "mihomo" -Direction Inbound -Action Allow -Program "${mihomoCorePath('mihomo')}" -Enabled True -Profile Any -ErrorAction SilentlyContinue
|
||||
New-NetFirewallRule -DisplayName "mihomo-alpha" -Direction Inbound -Action Allow -Program "${mihomoCorePath('mihomo-alpha')}" -Enabled True -Profile Any -ErrorAction SilentlyContinue
|
||||
New-NetFirewallRule -DisplayName "Mihomo Party" -Direction Inbound -Action Allow -Program "${exePath()}" -Enabled True -Profile Any -ErrorAction SilentlyContinue
|
||||
`
|
||||
|
||||
if (process.platform === 'win32') {
|
||||
await execPromise(removeCommand, { shell: 'powershell' })
|
||||
await execPromise(createCommand, { shell: 'powershell' })
|
||||
const rules = [
|
||||
{ name: 'mihomo', program: mihomoCorePath('mihomo') },
|
||||
{ name: 'mihomo-alpha', program: mihomoCorePath('mihomo-alpha') },
|
||||
{ name: 'Mihomo Party', program: exePath() }
|
||||
]
|
||||
for (const rule of rules) {
|
||||
await execPromise(`netsh advfirewall firewall delete rule name="${rule.name}"`, {
|
||||
shell: 'cmd'
|
||||
}).catch(() => {})
|
||||
await execPromise(
|
||||
`netsh advfirewall firewall add rule name="${rule.name}" dir=in action=allow program="${rule.program}" enable=yes profile=any`,
|
||||
{ shell: 'cmd' }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user