From 4997e098baa230c6a72511bc021e3f33407ccc6f Mon Sep 17 00:00:00 2001 From: ezequielnick <107352853+ezequielnick@users.noreply.github.com> Date: Wed, 13 Aug 2025 09:44:11 +0800 Subject: [PATCH] fix: remove core privilege check on non-windows --- src/main/core/manager.ts | 18 ++---------------- src/main/index.ts | 26 +++++++++++--------------- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/src/main/core/manager.ts b/src/main/core/manager.ts index 50439c8..fdf528e 100644 --- a/src/main/core/manager.ts +++ b/src/main/core/manager.ts @@ -487,22 +487,8 @@ export async function checkHighPrivilegeCore(): Promise { } if (process.platform === 'darwin' || process.platform === 'linux') { - const { stat, existsSync } = await import('fs') - const { promisify } = await import('util') - const statAsync = promisify(stat) - - if (!existsSync(corePath)) { - await managerLogger.info('Core file does not exist') - return false - } - - const stats = await statAsync(corePath) - const hasSetuid = (stats.mode & 0o4000) !== 0 - const isOwnedByRoot = stats.uid === 0 - - await managerLogger.info(`Core file stats - setuid: ${hasSetuid}, owned by root: ${isOwnedByRoot}, mode: ${stats.mode.toString(8)}`) - - return hasSetuid && isOwnedByRoot + await managerLogger.info('Non-Windows platform, skipping high privilege core check') + return false } } catch (error) { await managerLogger.error('Failed to check high privilege core', error) diff --git a/src/main/index.ts b/src/main/index.ts index c0a5b06..e102775 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -113,25 +113,21 @@ if (process.platform === 'win32' && !exePath().startsWith('C')) { app.commandLine.appendSwitch('in-process-gpu') } -// 内核检测 +// 运行内核检测 async function checkHighPrivilegeCoreEarly(): Promise { + if (process.platform !== 'win32') { + return + } + try { await initBasic() - // 应用管理员权限运行,跳过检测 - if (process.platform === 'win32') { - const { checkAdminPrivileges } = await import('./core/manager') - const isCurrentAppAdmin = await checkAdminPrivileges() + const { checkAdminPrivileges } = await import('./core/manager') + const isCurrentAppAdmin = await checkAdminPrivileges() - if (isCurrentAppAdmin) { - console.log('Current app is running as administrator, skipping privilege check') - return - } - } else if (process.platform === 'darwin' || process.platform === 'linux') { - if (process.getuid && process.getuid() === 0) { - console.log('Current app is running as root, skipping privilege check') - return - } + if (isCurrentAppAdmin) { + console.log('Current app is running as administrator, skipping privilege check') + return } const hasHighPrivilegeCore = await checkHighPrivilegeCore() @@ -155,7 +151,7 @@ async function checkHighPrivilegeCoreEarly(): Promise { if (choice === 0) { try { - // 非TUN重启 + // Windows 平台重启应用获取管理员权限 await restartAsAdmin(false) process.exit(0) } catch (error) {