From ae6cd88d9e07654ec922c5a3a9f122e68849dcab Mon Sep 17 00:00:00 2001 From: H3CoF6 <1707889225@qq.com> Date: Thu, 19 Mar 2026 03:04:28 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dsudo-prompt=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- electron/services/keyServiceLinux.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/electron/services/keyServiceLinux.ts b/electron/services/keyServiceLinux.ts index 14127ab..1d9e10b 100644 --- a/electron/services/keyServiceLinux.ts +++ b/electron/services/keyServiceLinux.ts @@ -3,7 +3,8 @@ import { join } from 'path' import { existsSync, readdirSync, statSync, readFileSync } from 'fs' import { execFile, exec } from 'child_process' import { promisify } from 'util' -import sudo from 'sudo-prompt' +import { createRequire } from 'module'; +const require = createRequire(import.meta.url); const execFileAsync = promisify(execFile) const execAsync = promisify(exec) @@ -12,6 +13,15 @@ type DbKeyResult = { success: boolean; key?: string; error?: string; logs?: stri type ImageKeyResult = { success: boolean; xorKey?: number; aesKey?: string; error?: string } export class KeyServiceLinux { + private sudo: any + + constructor() { + try { + this.sudo = require('sudo-prompt'); + } catch (e) { + console.error('Failed to load sudo-prompt', e); + } + } private getHelperPath(): string { const isPackaged = app.isPackaged @@ -99,7 +109,7 @@ export class KeyServiceLinux { const options = { name: 'WeFlow' } const command = `"${helperPath}" db_hook ${pid} ${targetAddr}` - sudo.exec(command, options, (error, stdout) => { + this.sudo.exec(command, options, (error, stdout) => { execAsync(`kill -CONT ${pid}`).catch(() => {}) if (error) { onStatus?.('授权失败或被取消', 2)