From 0dd69606883aa5d0f1c7a427e6760b454fc73cd5 Mon Sep 17 00:00:00 2001 From: Yejun Su Date: Fri, 20 Mar 2026 18:32:15 +0800 Subject: [PATCH] fix(remote-control): resync after restored model changes --- extensions/pi-remote-control/index.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/extensions/pi-remote-control/index.ts b/extensions/pi-remote-control/index.ts index dd6b9f8..bc449b9 100644 --- a/extensions/pi-remote-control/index.ts +++ b/extensions/pi-remote-control/index.ts @@ -29,6 +29,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; + + function scheduleSync(ctx: ExtensionContext): void { + if (pendingSyncTimer) clearTimeout(pendingSyncTimer); + pendingSyncTimer = setTimeout(() => { + pendingSyncTimer = undefined; + server?.sync(ctx); + updateStatus(ctx); + }, 0); + } // ── CLI flag ────────────────────────────────────────────────────────────── @@ -75,11 +85,18 @@ export default function remoteControl(pi: ExtensionAPI) { }); pi.on("session_switch", async (_event, ctx) => { - server?.sync(ctx); - updateStatus(ctx); + scheduleSync(ctx); + }); + + pi.on("model_select", async (_event, ctx) => { + scheduleSync(ctx); }); pi.on("session_shutdown", async () => { + if (pendingSyncTimer) { + clearTimeout(pendingSyncTimer); + pendingSyncTimer = undefined; + } if (server) { await server.stop(); server = undefined;