fix(remote-control): always sync on session switch even if turn started

This commit is contained in:
Yejun Su 2026-03-20 19:05:28 +08:00
parent b77c2a57b0
commit 9821efa370
No known key found for this signature in database
GPG Key ID: AD03A563F321CA44
1 changed files with 0 additions and 9 deletions

View File

@ -30,16 +30,11 @@ const QRCode = _require("qrcode") as { toString: (text: string, opts: any) => Pr
export default function remoteControl(pi: ExtensionAPI) { export default function remoteControl(pi: ExtensionAPI) {
let server: RemoteServer | undefined; let server: RemoteServer | undefined;
let pendingSyncTimer: ReturnType<typeof setTimeout> | undefined; let pendingSyncTimer: ReturnType<typeof setTimeout> | undefined;
let needsSyncOnIdle = false;
function scheduleSync(ctx: ExtensionContext): void { function scheduleSync(ctx: ExtensionContext): void {
if (pendingSyncTimer) clearTimeout(pendingSyncTimer); if (pendingSyncTimer) clearTimeout(pendingSyncTimer);
pendingSyncTimer = setTimeout(() => { pendingSyncTimer = setTimeout(() => {
pendingSyncTimer = undefined; pendingSyncTimer = undefined;
if (!ctx.isIdle()) {
needsSyncOnIdle = true;
return;
}
server?.sync(ctx); server?.sync(ctx);
updateStatus(ctx); updateStatus(ctx);
}, 0); }, 0);
@ -118,10 +113,6 @@ export default function remoteControl(pi: ExtensionAPI) {
pi.on("agent_end", async (_event, ctx) => { pi.on("agent_end", async (_event, ctx) => {
server?.broadcast({ type: "agent_end" }); server?.broadcast({ type: "agent_end" });
if (needsSyncOnIdle) {
needsSyncOnIdle = false;
server?.sync(ctx);
}
updateStatus(ctx); updateStatus(ctx);
}); });