diff --git a/src/common/utils/reboot.ts b/src/common/utils/reboot.ts index 7e4b6dad..23f3af6f 100644 --- a/src/common/utils/reboot.ts +++ b/src/common/utils/reboot.ts @@ -1,32 +1,30 @@ import { exit } from "process"; import { resolve } from "path"; -import { promisify } from "node:util"; -import { writeFile, writeFileSync } from "fs"; -import { exec } from "node:child_process"; -let execAsync = promisify(exec); +import { spawn } from "node:child_process"; +import { sleep } from "./helper"; + export async function rebootWithQuickLogin(uin: string) { let batScript = resolve(__dirname, './napcat.bat'); let batUtf8Script = resolve(__dirname, './napcat-utf8.bat'); let bashScript = resolve(__dirname, './napcat.sh'); if (process.platform === 'win32') { - console.log(process.platform); - let result = await execAsync(`timeout /t 5 /nobreak & ${batUtf8Script} -q ${uin}`); - console.log(result); + let subProcess = spawn(`start ${batUtf8Script} -q ${uin}`, { detached: true, windowsHide: false, env: process.env, shell: true, stdio: 'ignore'}); + subProcess.unref(); } else if (process.platform === 'linux') { - await execAsync(`timeout 5 & ${bashScript} -q ${uin}`); - // 启动bash执行脚本 + let subProcess = spawn(`${bashScript} -q ${uin}`, { detached: true, windowsHide: false, env: process.env, shell: true, stdio: 'ignore' }); + subProcess.unref(); } - //exit(0); + exit(0); } export async function rebootWithNormolLogin() { let batScript = resolve(__dirname, './napcat.bat'); let batUtf8Script = resolve(__dirname, './napcat-utf8.bat'); let bashScript = resolve(__dirname, './napcat.sh'); if (process.platform === 'win32') { - exec(`timeout /t 5 /nobreak & ${batUtf8Script}`); + spawn(`start ${batUtf8Script}`, { detached: true, windowsHide: false, env: process.env, shell: true }); } else if (process.platform === 'linux') { - exec(`timeout 5 & ${bashScript}`); - // 启动bash执行脚本 + spawn(`${bashScript}`, { detached: true, windowsHide: false, env: process.env, shell: true }); } + await sleep(500); exit(0); } \ No newline at end of file