mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-18 12:03:03 +00:00
Extension UI dialogs (select, confirm, input) now support a timeout option that auto-dismisses with a live countdown display. Simpler alternative to manually managing AbortSignal for timed dialogs. Also adds ExtensionUIDialogOptions type export and updates RPC mode to forward timeout to clients.
38 lines
841 B
TypeScript
38 lines
841 B
TypeScript
/**
|
|
* Reusable countdown timer for dialog components.
|
|
*/
|
|
|
|
import type { TUI } from "@mariozechner/pi-tui";
|
|
|
|
export class CountdownTimer {
|
|
private intervalId: ReturnType<typeof setInterval> | undefined;
|
|
private remainingSeconds: number;
|
|
|
|
constructor(
|
|
timeoutMs: number,
|
|
private tui: TUI | undefined,
|
|
private onTick: (seconds: number) => void,
|
|
private onExpire: () => void,
|
|
) {
|
|
this.remainingSeconds = Math.ceil(timeoutMs / 1000);
|
|
this.onTick(this.remainingSeconds);
|
|
|
|
this.intervalId = setInterval(() => {
|
|
this.remainingSeconds--;
|
|
this.onTick(this.remainingSeconds);
|
|
this.tui?.requestRender();
|
|
|
|
if (this.remainingSeconds <= 0) {
|
|
this.dispose();
|
|
this.onExpire();
|
|
}
|
|
}, 1000);
|
|
}
|
|
|
|
dispose(): void {
|
|
if (this.intervalId) {
|
|
clearInterval(this.intervalId);
|
|
this.intervalId = undefined;
|
|
}
|
|
}
|
|
}
|