mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-28 05:30:29 +08:00
automatically allow through the firewall
This commit is contained in:
parent
d6825fd7a9
commit
2130cacdb6
@ -1,10 +1,8 @@
|
||||
import { exec } from 'child_process'
|
||||
import { exePath } from '../utils/dirs'
|
||||
import { app } from 'electron'
|
||||
import fs from 'fs'
|
||||
|
||||
// 获取应用的可执行文件路径
|
||||
const exePath = app.getPath('exe')
|
||||
|
||||
const appName = 'mihomo-party'
|
||||
|
||||
const taskXml = `
|
||||
@ -45,7 +43,7 @@ const taskXml = `
|
||||
</Settings>
|
||||
<Actions Context="Author">
|
||||
<Exec>
|
||||
<Command>${exePath}</Command>
|
||||
<Command>${exePath()}</Command>
|
||||
</Exec>
|
||||
</Actions>
|
||||
</Task>
|
||||
@ -80,14 +78,14 @@ export function enableAutoRun(): void {
|
||||
if (process.platform === 'darwin') {
|
||||
app.setLoginItemSettings({
|
||||
openAtLogin: true,
|
||||
path: exePath
|
||||
path: exePath()
|
||||
})
|
||||
}
|
||||
if (process.platform === 'linux') {
|
||||
let desktop = `
|
||||
[Desktop Entry]
|
||||
Name=mihomo-party
|
||||
Exec=${exePath} %U
|
||||
Exec=${exePath()} %U
|
||||
Terminal=false
|
||||
Type=Application
|
||||
Icon=mihomo-party
|
||||
|
||||
@ -2,7 +2,9 @@ import {
|
||||
appConfigPath,
|
||||
controledMihomoConfigPath,
|
||||
dataDir,
|
||||
exePath,
|
||||
logDir,
|
||||
mihomoCorePath,
|
||||
mihomoTestDir,
|
||||
mihomoWorkDir,
|
||||
profileConfigPath,
|
||||
@ -23,6 +25,7 @@ import { startPacServer } from './server'
|
||||
import { triggerSysProxy } from './sysproxy'
|
||||
import { getAppConfig } from '../config'
|
||||
import { app } from 'electron'
|
||||
import { execSync } from 'child_process'
|
||||
|
||||
function initDirs(): void {
|
||||
if (!fs.existsSync(dataDir)) {
|
||||
@ -82,11 +85,38 @@ function initDeeplink(): void {
|
||||
}
|
||||
}
|
||||
|
||||
function initFirewall(): void {
|
||||
const removeCommand = `
|
||||
Remove-NetFirewallRule -DisplayName "mihomo" -ErrorAction SilentlyContinue
|
||||
Remove-NetFirewallRule -DisplayName "mihomo-alpha" -ErrorAction SilentlyContinue
|
||||
Remove-NetFirewallRule -DisplayName "Mihomo Party" -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') {
|
||||
try {
|
||||
execSync(removeCommand, { shell: 'powershell' })
|
||||
} catch {
|
||||
console.log('Remove-NetFirewallRule Failed')
|
||||
}
|
||||
try {
|
||||
execSync(createCommand, { shell: 'powershell' })
|
||||
} catch {
|
||||
console.log('New-NetFirewallRule Failed')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function init(): void {
|
||||
initDirs()
|
||||
initConfig()
|
||||
initFiles()
|
||||
initDeeplink()
|
||||
initFirewall()
|
||||
startPacServer().then(() => {
|
||||
triggerSysProxy(getAppConfig().sysProxy.enable)
|
||||
})
|
||||
|
||||
@ -4,6 +4,10 @@ import path from 'path'
|
||||
|
||||
export const dataDir = app.getPath('userData')
|
||||
|
||||
export function exePath(): string {
|
||||
return app.getPath('exe')
|
||||
}
|
||||
|
||||
export function resourcesDir(): string {
|
||||
if (is.dev) {
|
||||
return path.join(__dirname, '../../resources')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user