Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(rec): bound the prefs read, explain the disabled row, reconcile a failed write

Dmitry-Loburets118459f80e54
diff --git a/src/components/ai-edition/recordingImport.test.ts b/src/components/ai-edition/recordingImport.test.ts
index 487ed62b9..6d7f31e28 100644
--- a/src/components/ai-edition/recordingImport.test.ts
+++ b/src/components/ai-edition/recordingImport.test.ts
@@ -390,6 +390,21 @@ describe("fresh-recording auto-zoom", () => {
expect(consumeFreshRecordingAutoZoomPending()).toBe(false);
});
+ // The invoke is accepted and never answered — the shape `catch` cannot see. Left
+ // unbounded this held `freshRecordingAutoZoomSaveChain`, and therefore the metadata
+ // write queue awaiting it, for the life of the renderer.
+ it("gives up on a prefs read that never settles and applies zooms anyway", async () => {
+ markFreshRecordingAutoZoomPending(RECORDING_PATH);
+ // Never resolves, never rejects — the invoke the main process simply does not answer.
+ stubRecordingPrefsBridge(() => new Promise(() => undefined));
+ const next = await applyPendingFreshRecordingAutoZooms(documentWithClip(), {
+ prefsTimeoutMs: 10,
+ getTelemetry: async () => dwell(4000, 0.5, 0.5),
+ createId: (prefix) => `${prefix}_test`,
+ });
+ expect(next.zoomRanges).toHaveLength(1);
+ });
+
// A bridge that is missing or throwing says nothing about what the user chose, and
// the answer every installation had before the preference existed is "on".
it("treats an unreadable prefs bridge as on", async () => {
diff --git a/src/components/ai-edition/recordingImport.ts b/src/components/ai-edition/recordingImport.ts
index 2d47d7307..e27892cc1 100644
--- a/src/components/ai-edition/recordingImport.ts
+++ b/src/components/ai-edition/recordingImport.ts
@@ -75,6 +75,8 @@ export type ApplyFreshRecordingAutoZoomsDeps = {
saveTimeoutMs?: number;
/** Deadline for waiting on writes somebody else started. Tests shorten it. */
waitTimeoutMs?: number;
+ /** Deadline for the auto-zoom preference read. Tests shorten it. */
+ prefsTimeoutMs?: number;
};
/**
@@ -84,11 +86,23 @@ export type ApplyFreshRecordingAutoZoomsDeps = {
*
* An unreachable or throwing bridge reads as ON, which is what every installation did
* before the preference existed — a failed IPC call must not silently turn a feature off.
+ *
+ * Bounded for the same reason the write below is: this runs inside
+ * `freshRecordingAutoZoomSaveChain`, which `runLoadedMetadataWrite` awaits, so a main
+ * process that accepts the invoke and never answers would hold that queue slot — and
+ * every metadata write behind it — for the life of the renderer. `invoke` rejects on a
+ * throwing handler but never on a silent one, so the `catch` above cannot cover this.
+ * A deadline that expires says only "no answer yet", which reads as ON like every other
+ * unreadable answer.
*/
-async function readAutoZoomPref(): Promise<boolean> {
+async function readAutoZoomPref(timeoutMs = DOCUMENT_SAVES_WAIT_TIMEOUT_MS): Promise<boolean> {
try {
- const prefs = await window.electronAPI?.getRecordingPrefs?.();
- return prefs?.autoZoomEnabled !== false;
+ const read = (async () => {
+ const prefs = await window.electronAPI?.getRecordingPrefs?.();
+ return prefs?.autoZoomEnabled !== false;
+ })();
+ const settled = await saveWithDeadline(read, timeoutMs);
+ return settled === "timeout" ? true : settled;
} catch {
return true;
}
@@ -160,7 +174,7 @@ export async function applyPendingFreshRecordingAutoZooms(
clearFreshRecordingAutoZoomPending();
return document;
}
- const enabled = deps.enabled ?? (await readAutoZoomPref());
+ const enabled = deps.enabled ?? (await readAutoZoomPref(deps.prefsTimeoutMs));
if (!enabled) {
clearFreshRecordingAutoZoomPending();
return liveDocument(document);
diff --git a/src/components/ai-edition/v4/EditorShellV4.module.css b/src/components/ai-edition/v4/EditorShellV4.module.css
index dc37056a1..dd7898777 100644
--- a/src/components/ai-edition/v4/EditorShellV4.module.css
+++ b/src/components/ai-edition/v4/EditorShellV4.module.css
@@ -956,6 +956,19 @@
dropdown can't push the On/Off toggle off the panel edge (issue #624). */
min-width: 0;
}
+/* A row that has to explain itself wraps its reason onto a second line. Only the
+ auto-zoom row does this today, and only while the system cursor is selected. */
+.recRowWithHint {
+ flex-wrap: wrap;
+ row-gap: 6px;
+}
+.recRowHint {
+ flex-basis: 100%;
+ margin: 0;
+ color: var(--muted);
+ font-size: 12px;
+ line-height: 1.4;
+}
.recRowMuted {
display: inline-flex;
align-items: center;
diff --git a/src/components/ai-edition/v4/RecStage.test.tsx b/src/components/ai-edition/v4/RecStage.test.tsx
index 627f5c228..175bb0fa5 100644
--- a/src/components/ai-edition/v4/RecStage.test.tsx
+++ b/src/components/ai-edition/v4/RecStage.test.tsx
@@ -182,13 +182,40 @@ describe("RecStage controls", () => {
const button = screen.getByTestId("rec-auto-zoom-button");
await waitFor(() => expect(button).toBeDisabled());
expect(button).toHaveAttribute("aria-pressed", "false");
- expect(button).toHaveAttribute("title", "rec.autoZoomNeedsEditableCursor");
+ // A disabled button takes no focus and shows no tooltip, so the reason is a line
+ // in the row, tied to the button, rather than a title nobody on a keyboard reaches.
+ const hint = screen.getByText("rec.autoZoomNeedsEditableCursor");
+ expect(button).toHaveAttribute("aria-describedby", hint.id);
await act(async () => {
button.click();
});
expect(setRecordingPrefs).not.toHaveBeenCalled();
});
+ // The durable value is what the import path reads back, so a panel left showing Off
+ // after a rejected write would promise something the next take does not honour.
+ it("falls back to the stored value when the preference write is rejected", async () => {
+ const { getRecordingPrefs } = stubRecordingPrefs({
+ micEnabled: false,
+ cursorCaptureMode: "editable-overlay",
+ autoZoomEnabled: true,
+ });
+ const api = window.electronAPI as unknown as Record<string, unknown>;
+ const setRecordingPrefs = vi.fn(async () => {
+ throw new Error("write failed");
+ });
+ Object.assign(api, { setRecordingPrefs });
+ renderRecStage();
+ await waitFor(() => expect(getRecordingPrefs).toHaveBeenCalled());
+
+ const button = screen.getByTestId("rec-auto-zoom-button");
+ await act(async () => {
+ button.click();
+ });
+ expect(setRecordingPrefs).toHaveBeenCalledWith({ autoZoomEnabled: false });
+ await waitFor(() => expect(button).toHaveAttribute("aria-pressed", "true"));
+ });
+
it("waits for microphone discovery before starting the meter and normalizes default", async () => {
stubRecordingPrefs({
micEnabled: true,
diff --git a/src/components/ai-edition/v4/RecStage.tsx b/src/components/ai-edition/v4/RecStage.tsx
index 7d012f2ad..aa2b612d6 100644
--- a/src/components/ai-edition/v4/RecStage.tsx
+++ b/src/components/ai-edition/v4/RecStage.tsx
@@ -49,6 +49,9 @@ const DEFAULT_PREFS: RecordingPrefsState = {
autoZoomEnabled: true,
};
+/** Ties the disabled toggle to the line that explains why it is disabled. */
+const AUTO_ZOOM_HINT_ID = "rec-auto-zoom-hint";
+
function normalizedRecordingPrefs(prefs: Partial<RecordingPrefsState>): RecordingPrefsState {
return {
...DEFAULT_PREFS,
@@ -103,12 +106,24 @@ export function RecStage({
};
}, []);
const updatePrefs = (patch: Partial<RecordingPrefsState>) => {
- setPrefsState((prev) => {
- const next = { ...prev, ...patch };
- void window.electronAPI?.setRecordingPrefs?.(patch).catch((err) => {
- console.warn("[rec-stage] failed to persist the recording prefs:", err);
- });
- return next;
+ // The write is fired beside the optimistic patch rather than inside the updater:
+ // an updater is expected to be pure, and React re-invokes it under StrictMode,
+ // which sent every preference change twice.
+ setPrefsState((prev) => ({ ...prev, ...patch }));
+ void window.electronAPI?.setRecordingPrefs?.(patch).catch(async (err) => {
+ console.warn("[rec-stage] failed to persist the recording prefs:", err);
+ // Optimistic, then reconciled. The durable value is what the fresh-recording
+ // import reads back when it decides whether to place zooms, so a rejected
+ // write that left the patch on screen would have the user looking at Off
+ // while the next take still gets decorated. Re-read rather than invert the
+ // patch: a snapshot pushed while the write was in flight is newer than
+ // anything a rollback could restore.
+ try {
+ const current = await window.electronAPI?.getRecordingPrefs?.();
+ if (current) setPrefsState(normalizedRecordingPrefs(current));
+ } catch (readErr) {
+ console.warn("[rec-stage] failed to re-read the recording prefs:", readErr);
+ }
});
};
@@ -463,8 +478,12 @@ export function RecStage({
{/* Auto-zoom rides on the cursor telemetry the editable-overlay mode writes,
so the system cursor leaves nothing to place zooms from — the row reads
- Off and is inert there rather than promising a choice that cannot apply. */}
- <div className={styles.recRow}>
+ Off and is inert there rather than promising a choice that cannot apply.
+ Why it is inert is a second line in the row, not a title on the button:
+ a disabled button takes no focus and shows no tooltip to a keyboard or
+ screen-reader user, so a title would be the one explanation they cannot
+ reach. */}
+ <div className={`${styles.recRow}${cursorHighlight ? "" : ` ${styles.recRowWithHint}`}`}>
<div className={styles.recRowLabel}>
<ZoomIn size={15} />
{t("rec.autoZoom")}
@@ -475,11 +494,16 @@ export function RecStage({
className={`${styles.recToggleBtn}${autoZoom ? ` ${styles.on}` : ""}`}
aria-pressed={autoZoom}
disabled={!cursorHighlight}
- title={cursorHighlight ? undefined : t("rec.autoZoomNeedsEditableCursor")}
+ aria-describedby={cursorHighlight ? undefined : AUTO_ZOOM_HINT_ID}
onClick={() => updatePrefs({ autoZoomEnabled: !prefs.autoZoomEnabled })}
>
{autoZoom ? t("rec.on") : t("rec.off")}
</button>
+ {cursorHighlight ? null : (
+ <p id={AUTO_ZOOM_HINT_ID} className={styles.recRowHint}>
+ {t("rec.autoZoomNeedsEditableCursor")}
+ </p>
+ )}
</div>
{desktopIconsHint ? (