mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-12-01 01:05:30 +08:00
fix: 加固退出清理
退出应用时终止后台 进程 移除运行时动态安装 Python 依赖
This commit is contained in:
1 parent
313d0afff7
commit
17e3b51629
6 files changed
+60
-62
No files matched your search
@@ -1057,7 +1057,8 @@ export class AiSearchPipelineService {
|
||||
return result.evidence.map((item): AiSearchPipelineEvidence => {
|
||||
const rawConversationId = String(item.conversationId || '').trim()
|
||||
const contact =
|
||||
contactsById.get(rawConversationId) || contactsById.get(rawConversationId.toLocaleLowerCase())
|
||||
contactsById.get(rawConversationId) ||
|
||||
contactsById.get(rawConversationId.toLocaleLowerCase())
|
||||
return {
|
||||
...item,
|
||||
conversationId: contact?.md5 || rawConversationId,
|
||||
|
||||
@@ -265,27 +265,6 @@ export class PersonalWechatRuntimeManager {
|
||||
addModifiedWorkNotice(script)
|
||||
await chmod(executable, 0o755)
|
||||
|
||||
const pythonPackages = join(stagedDirectory, 'python')
|
||||
await mkdir(pythonPackages, { recursive: true })
|
||||
try {
|
||||
await execFileAsync('/usr/bin/env', [
|
||||
'python3',
|
||||
'-m',
|
||||
'pip',
|
||||
'install',
|
||||
'--disable-pip-version-check',
|
||||
'--no-compile',
|
||||
'--target',
|
||||
pythonPackages,
|
||||
'pilk==0.2.4'
|
||||
])
|
||||
} catch (error) {
|
||||
console.warn(
|
||||
'[PersonalWechatRuntime] pilk 安装失败,将使用 OneBot 内置的 Go SILK 编码器:',
|
||||
error
|
||||
)
|
||||
}
|
||||
|
||||
for (const required of [
|
||||
executable,
|
||||
script,
|
||||
|
||||
@@ -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 = ''
|
||||
|
||||
Reference in new issue
Block a user