mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2026-02-10 19:50:28 +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) {
|
||||
console.error('Failed to auto-enable TUN after admin restart:', error)
|
||||
}
|
||||
} else if (process.platform === 'win32') {
|
||||
} else {
|
||||
// 检查TUN配置与权限的匹配
|
||||
await validateTunPermissionsOnStartup()
|
||||
}
|
||||
}
|
||||
|
||||
export async function validateTunPermissionsOnStartup(): Promise<void> {
|
||||
try {
|
||||
const hasAdminPrivileges = await checkAdminPrivileges()
|
||||
const { tun } = await getControledMihomoConfig()
|
||||
|
||||
if (hasAdminPrivileges && !tun?.enable) {
|
||||
console.log('Running with admin privileges but TUN is disabled')
|
||||
if (!tun?.enable) {
|
||||
return
|
||||
}
|
||||
|
||||
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('adminPrivilegesDetected', { tunEnabled: false })
|
||||
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 check admin privileges on startup:', error)
|
||||
}
|
||||
console.error('Failed to validate TUN permissions on startup:', error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user