optimized tun enable logic
Some checks are pending
Build / windows (arm64) (push) Waiting to run
Build / windows (ia32) (push) Waiting to run
Build / windows (x64) (push) Waiting to run
Build / linux (arm64) (push) Waiting to run
Build / linux (x64) (push) Waiting to run
Build / macos (arm64) (push) Waiting to run
Build / macos (x64) (push) Waiting to run
Build / updater (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-bin) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-electron) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-electron-bin) (push) Blocked by required conditions
Build / aur-git-updater (push) Waiting to run

This commit is contained in:
pompurin404 2024-09-05 12:02:12 +08:00
parent 253e2f20df
commit 8341588a08
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
} from '../utils/dirs'
import { generateProfile } from './factory'
import { getAppConfig, getControledMihomoConfig, patchAppConfig } from '../config'
import { dialog, safeStorage } from 'electron'
import {
getAppConfig,
getControledMihomoConfig,
patchAppConfig,
patchControledMihomoConfig
} from '../config'
import { dialog, ipcMain, safeStorage } from 'electron'
import {
startMihomoTraffic,
startMihomoConnections,
@ -74,6 +79,9 @@ export async function startCore(): Promise<Promise<void>[]> {
return new Promise((resolve, reject) => {
child.stdout?.on('data', async (data) => {
if (data.toString().includes('configure tun interface: operation not permitted')) {
patchControledMihomoConfig({ tun: { enable: false } })
mainWindow?.webContents.send('controledMihomoConfigUpdated')
ipcMain.emit('updateTrayMenu')
reject('虚拟网卡启动失败, 请尝试手动授予内核权限')
}
if (data.toString().includes('External controller listen error')) {

View File

@ -71,7 +71,9 @@ const TunSwitcher: React.FC = () => {
try {
const encrypted = await encryptString(password)
await patchAppConfig({ encryptedPassword: encrypted })
await patchControledMihomoConfig({ tun: { enable }, dns: { enable: true } })
await restartCore()
window.electron.ipcRenderer.send('updateTrayMenu')
setOpenPasswordModal(false)
} catch (e) {
alert(e)