Add pipe-watcher and manual refresh for hooks

Introduce a background pipe-watcher and per-PID operation serialization in HookManager to reliably detect and reconnect to SnowLuma pipes, reduce races, and remove the previous connect retry loop. Add new status 'connecting' and a refreshProcess API endpoint to force a probe/reconcile for a PID. Implement QqHookClient.listLivePipes() (and isClosed/probePipe updates) to enumerate live mojo pipes efficiently. Simplify client teardown logic and improve state transitions/logging. Update web UI: add a Refresh button, track inflight process ops, show connecting status and updated action messages. Update shared types to include the new 'connecting' status.
This commit is contained in:
手瓜一十雪 committed 2026-05-06 16:10:14 +08:00
1 parent 2e340f58a8
commit 4b02367a5f
6 files changed
+435 -138

No files matched your search

+27 -7
View File
@@ -253,6 +253,10 @@ export class QqHookClient extends EventEmitter {
return this.loginState.loggedIn;
}
get isClosed(): boolean {
return this.closed;
}
get currentUin(): string {
return this.loginState.uin;
}
@@ -289,19 +293,35 @@ export class QqHookClient extends EventEmitter {
* opening the pipe, so probing cannot disturb the first real client connect.
*/
static async probePipe(pid: number): Promise<boolean> {
const live = await QqHookClient.listLivePipes();
return live.has(pid);
}
/**
* Enumerate every PID currently hosting a SnowLuma `mojo.<pid>.control` pipe
* in a single filesystem listing. The HookManager's pipe-watcher uses this
* to drive connect/reconnect decisions without per-PID stat calls.
*/
static async listLivePipes(): Promise<Set<number>> {
const result = new Set<number>();
try {
const pipeFileName = process.platform === 'win32'
? `mojo.${pid}.control`
: `mojo.${pid}.control.sock`;
if (process.platform === 'win32') {
const names = await fs.readdir('\\\\.\\pipe\\');
return names.some(name => name.toLowerCase() === pipeFileName.toLowerCase());
for (const name of names) {
const m = /^mojo\.(\d+)\.control$/i.exec(name);
if (m) result.add(Number(m[1]));
}
} else {
const names = await fs.readdir(linuxRuntimeDir());
for (const name of names) {
const m = /^mojo\.(\d+)\.control\.sock$/.exec(name);
if (m) result.add(Number(m[1]));
}
}
const names = await fs.readdir(linuxRuntimeDir());
return names.includes(pipeFileName);
} catch {
return false;
/* directory missing or inaccessible — treat as no live pipes */
}
return result;
}
async connect(): Promise<QqHookHello> {