Merge pull request #21 from SnowLuma/dev
chore: promote dev → main (a7b3809)
This commit is contained in:
1 file changed
+6
-10
@@ -76,9 +76,7 @@ export class HookManager {
|
|||||||
|
|
||||||
async listProcesses(): Promise<HookProcessInfo[]> {
|
async listProcesses(): Promise<HookProcessInfo[]> {
|
||||||
const processes = listHookProcesses();
|
const processes = listHookProcesses();
|
||||||
const seen = new Set<number>();
|
|
||||||
for (const proc of processes) {
|
for (const proc of processes) {
|
||||||
seen.add(proc.pid);
|
|
||||||
const state = this.ensureState(proc.pid);
|
const state = this.ensureState(proc.pid);
|
||||||
state.name = proc.name || state.name;
|
state.name = proc.name || state.name;
|
||||||
state.path = proc.path || state.path;
|
state.path = proc.path || state.path;
|
||||||
@@ -87,11 +85,6 @@ export class HookManager {
|
|||||||
for (const proc of processes) {
|
for (const proc of processes) {
|
||||||
result.push(this.toPublicInfo(this.ensureState(proc.pid)));
|
result.push(this.toPublicInfo(this.ensureState(proc.pid)));
|
||||||
}
|
}
|
||||||
for (const state of this.states.values()) {
|
|
||||||
if (!seen.has(state.pid) && (state.injected || state.client)) {
|
|
||||||
result.push(this.toPublicInfo(state));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result.sort((a, b) => a.pid - b.pid);
|
return result.sort((a, b) => a.pid - b.pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,6 +309,7 @@ export class HookManager {
|
|||||||
try {
|
try {
|
||||||
const livePipes = await QqHookClient.listLivePipes();
|
const livePipes = await QqHookClient.listLivePipes();
|
||||||
const processes = listHookProcesses();
|
const processes = listHookProcesses();
|
||||||
|
const runningSet = new Set(processes.map(p => p.pid));
|
||||||
|
|
||||||
// Refresh metadata + ensure a state entry exists for each known PID.
|
// Refresh metadata + ensure a state entry exists for each known PID.
|
||||||
for (const proc of processes) {
|
for (const proc of processes) {
|
||||||
@@ -325,6 +319,7 @@ export class HookManager {
|
|||||||
}
|
}
|
||||||
// Auto-detect hooks that survived a SnowLuma restart or failed unload.
|
// Auto-detect hooks that survived a SnowLuma restart or failed unload.
|
||||||
for (const pid of livePipes) {
|
for (const pid of livePipes) {
|
||||||
|
if (!runningSet.has(pid)) continue;
|
||||||
const state = this.ensureState(pid);
|
const state = this.ensureState(pid);
|
||||||
if (!state.injected) {
|
if (!state.injected) {
|
||||||
state.injected = true;
|
state.injected = true;
|
||||||
@@ -334,14 +329,15 @@ export class HookManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const runningSet = new Set(processes.map(p => p.pid));
|
|
||||||
const tasks: Promise<unknown>[] = [];
|
const tasks: Promise<unknown>[] = [];
|
||||||
for (const state of [...this.states.values()]) {
|
for (const state of [...this.states.values()]) {
|
||||||
const alivePipe = livePipes.has(state.pid);
|
const alivePipe = livePipes.has(state.pid);
|
||||||
const aliveProc = runningSet.has(state.pid);
|
const aliveProc = runningSet.has(state.pid);
|
||||||
|
|
||||||
// Reap stale state entries that have nothing left to do.
|
if (!aliveProc) {
|
||||||
if (!aliveProc && !alivePipe && !state.injected && !state.client) {
|
const wasLoggedIn = state.loggedIn;
|
||||||
|
this.tearDownClient(state);
|
||||||
|
if (wasLoggedIn) this.bridgeManager.onPidDisconnected(state.pid);
|
||||||
this.states.delete(state.pid);
|
this.states.delete(state.pid);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user