feat(core): record runtime status while waiting to sign in
Refresh the bundled runtime binaries.
This commit is contained in:
9 files changed
+30
-7
No files matched your search
@@ -103,6 +103,7 @@ export class HookSession extends EventEmitter {
|
||||
private disposed = false;
|
||||
private loginProbeTimer: ReturnType<typeof setInterval> | null = null;
|
||||
private probing = false;
|
||||
private lastProbeFailure = '';
|
||||
private acceptedLoginHintUin = '';
|
||||
private loginHintAttemptUin = '';
|
||||
private loginHintAttempts = 0;
|
||||
@@ -670,6 +671,7 @@ export class HookSession extends EventEmitter {
|
||||
|
||||
private startLoginReconcile(): void {
|
||||
if (this.loginProbeTimer || this.disposed) return;
|
||||
this.log.info('awaiting login: PID=%d', this.pid);
|
||||
void this.probeLoginOnce(); // immediate — catch already-logged-in fast
|
||||
this.loginProbeTimer = setInterval(() => void this.probeLoginOnce(), LOGIN_RECONCILE_INTERVAL_MS);
|
||||
this.loginProbeTimer.unref?.();
|
||||
@@ -694,11 +696,12 @@ export class HookSession extends EventEmitter {
|
||||
try {
|
||||
info = await this.probeLogin(this.pid);
|
||||
} catch (error) {
|
||||
this.log.trace(
|
||||
'login identity probe failed: PID=%d err=%s',
|
||||
this.pid,
|
||||
errMsg(error),
|
||||
);
|
||||
const message = errMsg(error);
|
||||
const note = `${this.pid}:${message}`;
|
||||
if (this.lastProbeFailure !== note) {
|
||||
this.lastProbeFailure = note;
|
||||
this.log.warn('login probe failed: PID=%d err=%s', this.pid, message);
|
||||
}
|
||||
return; // best-effort; the interval retries
|
||||
}
|
||||
// The await yielded — re-check we still want this before mutating state.
|
||||
@@ -764,6 +767,7 @@ export class HookSession extends EventEmitter {
|
||||
this.loginHintAttempts = 0;
|
||||
this.nextLoginHintAt = 0;
|
||||
this.nextLoginIdentityObservationAt = 0;
|
||||
this.lastProbeFailure = '';
|
||||
}
|
||||
|
||||
private handlePacket(packet: QqHookPacket): void {
|
||||
|
||||
@@ -6,6 +6,15 @@ import { promisify } from 'util';
|
||||
|
||||
const execAsync = promisify(exec);
|
||||
const log = createLogger('LoginProbe');
|
||||
const probeNotes = new Map<number, string>();
|
||||
|
||||
function noteProbe(pid: number, result: string, ports: number, processes: number | null): void {
|
||||
const processText = processes === null ? '' : ` processes=${processes}`;
|
||||
const message = `login probe: PID=${pid} result=${result} ports=${ports}${processText}`;
|
||||
if (probeNotes.get(pid) === message) return;
|
||||
probeNotes.set(pid, message);
|
||||
log.info(message);
|
||||
}
|
||||
|
||||
const CONNECTION_TIMEOUT_MS = 500;
|
||||
const COMMAND_TIMEOUT_MS = 1500;
|
||||
@@ -164,13 +173,18 @@ async function getProcessPorts(pid: number): Promise<number[] | null> {
|
||||
|
||||
async function probeQqLoginInfoInternal(pid: number): Promise<QqPortLoginInfo | null> {
|
||||
const ports = await getProcessPorts(pid);
|
||||
if (ports === null) return null;
|
||||
if (ports === null) {
|
||||
noteProbe(pid, 'unavailable', 0, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (ports.length === 0) {
|
||||
const totalPids = await getQqProcessCount();
|
||||
if (totalPids < LOGGED_OUT_PROCESS_COUNT_MAX) {
|
||||
noteProbe(pid, 'no-ports', 0, totalPids);
|
||||
return { port: 0, uin: '', identityKnown: false };
|
||||
}
|
||||
noteProbe(pid, 'inconclusive', 0, totalPids);
|
||||
return null;
|
||||
}
|
||||
const ODD_PT_PORTS = [4301, 4303, 4305, 4307, 4309];
|
||||
@@ -196,16 +210,20 @@ async function probeQqLoginInfoInternal(pid: number): Promise<QqPortLoginInfo |
|
||||
} else {
|
||||
const totalPids = await getQqProcessCount();
|
||||
if (totalPids < LOGGED_OUT_PROCESS_COUNT_MAX) {
|
||||
noteProbe(pid, 'no-ports', ports.length, totalPids);
|
||||
return {
|
||||
port: ports[0] || 0,
|
||||
uin: '',
|
||||
identityKnown: false,
|
||||
};
|
||||
}
|
||||
noteProbe(pid, 'inconclusive', ports.length, totalPids);
|
||||
return null;
|
||||
}
|
||||
|
||||
// Background discovery must remain passive. Interactive application
|
||||
// endpoints are deliberately excluded from automatic probing.
|
||||
noteProbe(pid, 'no-match', ptPortsToTry.length, null);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -676,7 +676,8 @@ describe('probeQqLoginInfo — overall deadline', () => {
|
||||
uin: '',
|
||||
identityKnown: false,
|
||||
});
|
||||
expect(warnings).toEqual([]);
|
||||
await probeQqLoginInfo(9002);
|
||||
expect(warnings).toEqual(['login probe: PID=9002 result=no-ports ports=0 processes=2']);
|
||||
} finally {
|
||||
unsubscribe();
|
||||
setLogLevel(previousLevel);
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in new issue
Block a user