Make the transport control inert during a start or stop

Both open or release a microphone and, in Follow mode, a speech model —
neither is instant. Nothing stopped a second click, or a held Enter/Space key,
from firing before the first attempt finished, which would race two attempts
against the same input device rather than one clean transition.

The button now disables itself for the duration, and the handler guards the
same window so a keyboard repeat is covered too, not just a mouse double-click.
This commit is contained in:
CRTkafa 2026-08-26 19:27:46 +07:00
parent d945b43997
commit 81ec9ce219
2 changed files with 30 additions and 3 deletions

View file

@ -80,6 +80,7 @@ Today we are shipping something I have wanted for a long time.
let panelOpen = $state(false); let panelOpen = $state(false);
let running = $state(false); let running = $state(false);
let transitioning = $state(false);
let paused = $state(false); let paused = $state(false);
let muted = $state(false); let muted = $state(false);
let status = $state(""); let status = $state("");
@ -247,8 +248,19 @@ Today we are shipping something I have wanted for a long time.
} }
async function toggleRun() { async function toggleRun() {
// start() and stop() both open or release a microphone and a model, which
// take real time to settle. Without this guard, a second click before the
// first finishes would race two attempts against the same device — the
// button is also disabled while this is true, but a guard here covers
// activation via the keyboard's repeat-on-hold too.
if (transitioning) return;
transitioning = true;
try {
if (running) await stop(); if (running) await stop();
else await start(); else await start();
} finally {
transitioning = false;
}
} }
async function start() { async function start() {
@ -670,6 +682,7 @@ Today we are shipping something I have wanted for a long time.
{paused} {paused}
{level} {level}
listening={needsMicrophone && !muted} listening={needsMicrophone && !muted}
disabled={transitioning}
onclick={toggleRun} onclick={toggleRun}
/> />

View file

@ -17,10 +17,19 @@
/** Microphone level, 0..1. Ignored when the mode has no microphone. */ /** Microphone level, 0..1. Ignored when the mode has no microphone. */
level: number; level: number;
listening: boolean; listening: boolean;
/**
* True while a start or stop is already in flight.
*
* Both open a microphone and a model that take real time to settle, so a
* second click before the first finishes would race two attempts against
* the same device — this makes the button inert until one completes.
*/
disabled?: boolean;
onclick: () => void; onclick: () => void;
} }
let { running, paused, level, listening, onclick }: Props = $props(); let { running, paused, level, listening, disabled = false, onclick }: Props =
$props();
let swell = $state(0); let swell = $state(0);
let frame = 0; let frame = 0;
@ -52,6 +61,7 @@
class:paused class:paused
class:calm class:calm
style="--swell:{swell}" style="--swell:{swell}"
{disabled}
{onclick} {onclick}
aria-label={running ? "Stop the prompter" : "Start the prompter"} aria-label={running ? "Stop the prompter" : "Start the prompter"}
> >
@ -76,6 +86,10 @@
cursor: pointer; cursor: pointer;
isolation: isolate; isolation: isolate;
} }
.liquid:disabled {
cursor: default;
opacity: 0.7;
}
.liquid:focus-visible { .liquid:focus-visible {
outline: 2px solid var(--accent); outline: 2px solid var(--accent);
outline-offset: 4px; outline-offset: 4px;