optimized tun enable logic

This commit is contained in:
pompurin404 2024-09-05 12:02:12 +08:00
parent 253e2f20df
commit 8e00cb4bbf
No known key found for this signature in database
2 changed files with 12 additions and 2 deletions

View File

@ -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')) {

View File

@ -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)