mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-03-24 23:06:51 +00:00
fix: 修复sudo-prompt的问题
This commit is contained in:
@@ -3,7 +3,8 @@ import { join } from 'path'
|
|||||||
import { existsSync, readdirSync, statSync, readFileSync } from 'fs'
|
import { existsSync, readdirSync, statSync, readFileSync } from 'fs'
|
||||||
import { execFile, exec } from 'child_process'
|
import { execFile, exec } from 'child_process'
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'util'
|
||||||
import sudo from 'sudo-prompt'
|
import { createRequire } from 'module';
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
const execFileAsync = promisify(execFile)
|
const execFileAsync = promisify(execFile)
|
||||||
const execAsync = promisify(exec)
|
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 }
|
type ImageKeyResult = { success: boolean; xorKey?: number; aesKey?: string; error?: string }
|
||||||
|
|
||||||
export class KeyServiceLinux {
|
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 {
|
private getHelperPath(): string {
|
||||||
const isPackaged = app.isPackaged
|
const isPackaged = app.isPackaged
|
||||||
@@ -99,7 +109,7 @@ export class KeyServiceLinux {
|
|||||||
const options = { name: 'WeFlow' }
|
const options = { name: 'WeFlow' }
|
||||||
const command = `"${helperPath}" db_hook ${pid} ${targetAddr}`
|
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(() => {})
|
execAsync(`kill -CONT ${pid}`).catch(() => {})
|
||||||
if (error) {
|
if (error) {
|
||||||
onStatus?.('授权失败或被取消', 2)
|
onStatus?.('授权失败或被取消', 2)
|
||||||
|
|||||||
Reference in New Issue
Block a user