From b77c2a57b00c382a9bf85370ac943f99769f901f Mon Sep 17 00:00:00 2001 From: Yejun Su Date: Fri, 20 Mar 2026 18:51:11 +0800 Subject: [PATCH] fix(remote-control): re-check idle state inside delayed sync callback --- extensions/pi-remote-control/index.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/extensions/pi-remote-control/index.ts b/extensions/pi-remote-control/index.ts index 3ad9d81..322e4a4 100644 --- a/extensions/pi-remote-control/index.ts +++ b/extensions/pi-remote-control/index.ts @@ -30,11 +30,16 @@ const QRCode = _require("qrcode") as { toString: (text: string, opts: any) => Pr export default function remoteControl(pi: ExtensionAPI) { let server: RemoteServer | undefined; let pendingSyncTimer: ReturnType | undefined; + let needsSyncOnIdle = false; function scheduleSync(ctx: ExtensionContext): void { if (pendingSyncTimer) clearTimeout(pendingSyncTimer); pendingSyncTimer = setTimeout(() => { pendingSyncTimer = undefined; + if (!ctx.isIdle()) { + needsSyncOnIdle = true; + return; + } server?.sync(ctx); updateStatus(ctx); }, 0); @@ -113,6 +118,10 @@ export default function remoteControl(pi: ExtensionAPI) { pi.on("agent_end", async (_event, ctx) => { server?.broadcast({ type: "agent_end" }); + if (needsSyncOnIdle) { + needsSyncOnIdle = false; + server?.sync(ctx); + } updateStatus(ctx); });