mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
optimized tun enable logic
This commit is contained in:
parent
253e2f20df
commit
8e00cb4bbf
@ -8,8 +8,13 @@ import {
|
|||||||
mihomoWorkDir
|
mihomoWorkDir
|
||||||
} from '../utils/dirs'
|
} from '../utils/dirs'
|
||||||
import { generateProfile } from './factory'
|
import { generateProfile } from './factory'
|
||||||
import { getAppConfig, getControledMihomoConfig, patchAppConfig } from '../config'
|
import {
|
||||||
import { dialog, safeStorage } from 'electron'
|
getAppConfig,
|
||||||
|
getControledMihomoConfig,
|
||||||
|
patchAppConfig,
|
||||||
|
patchControledMihomoConfig
|
||||||
|
} from '../config'
|
||||||
|
import { dialog, ipcMain, safeStorage } from 'electron'
|
||||||
import {
|
import {
|
||||||
startMihomoTraffic,
|
startMihomoTraffic,
|
||||||
startMihomoConnections,
|
startMihomoConnections,
|
||||||
@ -74,6 +79,9 @@ export async function startCore(): Promise<Promise<void>[]> {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
child.stdout?.on('data', async (data) => {
|
child.stdout?.on('data', async (data) => {
|
||||||
if (data.toString().includes('configure tun interface: operation not permitted')) {
|
if (data.toString().includes('configure tun interface: operation not permitted')) {
|
||||||
|
patchControledMihomoConfig({ tun: { enable: false } })
|
||||||
|
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
||||||
|
ipcMain.emit('updateTrayMenu')
|
||||||
reject('虚拟网卡启动失败, 请尝试手动授予内核权限')
|
reject('虚拟网卡启动失败, 请尝试手动授予内核权限')
|
||||||
}
|
}
|
||||||
if (data.toString().includes('External controller listen error')) {
|
if (data.toString().includes('External controller listen error')) {
|
||||||
|
|||||||
@ -71,7 +71,9 @@ const TunSwitcher: React.FC = () => {
|
|||||||
try {
|
try {
|
||||||
const encrypted = await encryptString(password)
|
const encrypted = await encryptString(password)
|
||||||
await patchAppConfig({ encryptedPassword: encrypted })
|
await patchAppConfig({ encryptedPassword: encrypted })
|
||||||
|
await patchControledMihomoConfig({ tun: { enable: true }, dns: { enable: true } })
|
||||||
await restartCore()
|
await restartCore()
|
||||||
|
window.electron.ipcRenderer.send('updateTrayMenu')
|
||||||
setOpenPasswordModal(false)
|
setOpenPasswordModal(false)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
alert(e)
|
alert(e)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user