fix: 加固退出清理

退出应用时终止后台 进程
移除运行时动态安装 Python 依赖
This commit is contained in:
Wxw-Gu committed 2026-08-21 15:37:01 +08:00
1 parent 313d0afff7
commit 17e3b51629
6 files changed
+60 -62

No files matched your search

@@ -372,20 +372,29 @@ async function readOneBotProcessInfo(): Promise<OneBotProcessInfo | undefined> {
async function terminateOneBot(info: OneBotProcessInfo): Promise<void> {
if (!/(^|\/)onebot(?:\s|$)/.test(info.command)) return
await terminateProcess(info.pid)
}
async function terminateProcess(pid: number): Promise<void> {
try {
process.kill(info.pid, 'SIGTERM')
process.kill(pid, 'SIGTERM')
} catch {
return
}
const startedAt = Date.now()
while (Date.now() - startedAt < STOP_TIMEOUT_MS) {
try {
process.kill(info.pid, 0)
process.kill(pid, 0)
await new Promise((resolve) => setTimeout(resolve, 100))
} catch {
return
}
}
try {
process.kill(pid, 'SIGKILL')
} catch {
// The process exited between the last liveness check and the forced stop.
}
}
async function requestWithTimeout(
@@ -605,18 +614,11 @@ export class PersonalWechatSendService {
return status
}
stop(): void {
const child = this.child
this.child = null
this.startPromise = null
// A second Attach to the same WeChat process is unstable. Leave OneBot alive;
// it monitors the WeChat PID and exits when that process ends.
if (child && child.exitCode === null) child.unref()
}
async terminate(): Promise<void> {
const trackedPid = this.child?.pid
const oneBot = await readOneBotProcessInfo()
if (oneBot) await terminateOneBot(oneBot)
if (trackedPid && trackedPid !== oneBot?.pid) await terminateProcess(trackedPid)
this.child = null
this.startPromise = null
this.lastError = ''