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:
parent
d945b43997
commit
81ec9ce219
2 changed files with 30 additions and 3 deletions
|
|
@ -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() {
|
||||||
if (running) await stop();
|
// start() and stop() both open or release a microphone and a model, which
|
||||||
else await start();
|
// 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();
|
||||||
|
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}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue