diff --git a/frontend/src/capture/SessionCapture.svelte b/frontend/src/capture/SessionCapture.svelte index 8e200b4..7f8ae58 100644 --- a/frontend/src/capture/SessionCapture.svelte +++ b/frontend/src/capture/SessionCapture.svelte @@ -71,12 +71,17 @@ let fileInput: HTMLInputElement; // Auto-run the mask so the overlay (and preview) populate without the owner - // pressing Approve first. `controlKey` changes only on sheet/sensitivity - // edits (never on the overlay itself), so this fires on entry and on each - // control change - but not when approveMask settles the overlay (no loop). + // pressing Approve first. Debounced 500ms after the user stops adjusting the + // sheet/sensitivity, so rapid slider drags don't trigger a flood of async + // mask runs (and an in-flight run can't clobber the state around an Approve + // click). Keyed on control values, not the overlay, so settling never loops. + let maskRunTimer = 0; $: controlKey = kind === 'mask' && cap.control ? `${cap.control.sheet}:${cap.control.sensitivity}` : null; $: if (controlKey && cap.source && cap.source.widthPx > 0) { - void session.approveMask(); + clearTimeout(maskRunTimer); + maskRunTimer = setTimeout(() => { + void session.approveMask(); + }, 500); } function pickFiles(e: Event) {