mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-11 04:00:32 +08:00
feat: validate TUN configuration and permission compatibility
This commit is contained in:
parent
58732ce653
commit
b5ee701530
@ -458,19 +458,37 @@ export async function checkAdminRestartForTun(): Promise<void> {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to auto-enable TUN after admin restart:', error)
|
console.error('Failed to auto-enable TUN after admin restart:', error)
|
||||||
}
|
}
|
||||||
} else if (process.platform === 'win32') {
|
} else {
|
||||||
try {
|
// 检查TUN配置与权限的匹配
|
||||||
const hasAdminPrivileges = await checkAdminPrivileges()
|
await validateTunPermissionsOnStartup()
|
||||||
const { tun } = await getControledMihomoConfig()
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (hasAdminPrivileges && !tun?.enable) {
|
export async function validateTunPermissionsOnStartup(): Promise<void> {
|
||||||
console.log('Running with admin privileges but TUN is disabled')
|
try {
|
||||||
const { mainWindow } = await import('../index')
|
const { tun } = await getControledMihomoConfig()
|
||||||
mainWindow?.webContents.send('adminPrivilegesDetected', { tunEnabled: false })
|
|
||||||
}
|
if (!tun?.enable) {
|
||||||
} catch (error) {
|
return
|
||||||
console.error('Failed to check admin privileges on startup:', error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const hasPermissions = await checkMihomoCorePermissions()
|
||||||
|
|
||||||
|
if (!hasPermissions) {
|
||||||
|
console.warn('TUN is enabled but insufficient permissions detected, auto-disabling TUN...')
|
||||||
|
|
||||||
|
await patchControledMihomoConfig({ tun: { enable: false } })
|
||||||
|
|
||||||
|
const { mainWindow } = await import('../index')
|
||||||
|
mainWindow?.webContents.send('controledMihomoConfigUpdated')
|
||||||
|
ipcMain.emit('updateTrayMenu')
|
||||||
|
|
||||||
|
console.log('TUN auto-disabled due to insufficient permissions')
|
||||||
|
} else {
|
||||||
|
console.log('TUN permissions validated successfully')
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to validate TUN permissions on startup:', error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user