fix: 修复重启 但win无法及时结束父进程

This commit is contained in:
手瓜一十雪 2024-05-13 13:44:23 +08:00
parent f74a83bc46
commit db63675b8e

View File

@ -1,32 +1,30 @@
import { exit } from "process"; import { exit } from "process";
import { resolve } from "path"; import { resolve } from "path";
import { promisify } from "node:util"; import { spawn } from "node:child_process";
import { writeFile, writeFileSync } from "fs"; import { sleep } from "./helper";
import { exec } from "node:child_process";
let execAsync = promisify(exec);
export async function rebootWithQuickLogin(uin: string) { export async function rebootWithQuickLogin(uin: string) {
let batScript = resolve(__dirname, './napcat.bat'); let batScript = resolve(__dirname, './napcat.bat');
let batUtf8Script = resolve(__dirname, './napcat-utf8.bat'); let batUtf8Script = resolve(__dirname, './napcat-utf8.bat');
let bashScript = resolve(__dirname, './napcat.sh'); let bashScript = resolve(__dirname, './napcat.sh');
if (process.platform === 'win32') { if (process.platform === 'win32') {
console.log(process.platform); let subProcess = spawn(`start ${batUtf8Script} -q ${uin}`, { detached: true, windowsHide: false, env: process.env, shell: true, stdio: 'ignore'});
let result = await execAsync(`timeout /t 5 /nobreak & ${batUtf8Script} -q ${uin}`); subProcess.unref();
console.log(result);
} else if (process.platform === 'linux') { } else if (process.platform === 'linux') {
await execAsync(`timeout 5 & ${bashScript} -q ${uin}`); let subProcess = spawn(`${bashScript} -q ${uin}`, { detached: true, windowsHide: false, env: process.env, shell: true, stdio: 'ignore' });
// 启动bash执行脚本 subProcess.unref();
} }
//exit(0); exit(0);
} }
export async function rebootWithNormolLogin() { export async function rebootWithNormolLogin() {
let batScript = resolve(__dirname, './napcat.bat'); let batScript = resolve(__dirname, './napcat.bat');
let batUtf8Script = resolve(__dirname, './napcat-utf8.bat'); let batUtf8Script = resolve(__dirname, './napcat-utf8.bat');
let bashScript = resolve(__dirname, './napcat.sh'); let bashScript = resolve(__dirname, './napcat.sh');
if (process.platform === 'win32') { 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') { } else if (process.platform === 'linux') {
exec(`timeout 5 & ${bashScript}`); spawn(`${bashScript}`, { detached: true, windowsHide: false, env: process.env, shell: true });
// 启动bash执行脚本
} }
await sleep(500);
exit(0); exit(0);
} }