fix(remote-control): resync after restored model changes

This commit is contained in:
Yejun Su 2026-03-20 18:32:15 +08:00
parent 33403bd030
commit 0dd6960688
No known key found for this signature in database
GPG Key ID: AD03A563F321CA44
1 changed files with 19 additions and 2 deletions

View File

@ -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<typeof setTimeout> | 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;