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(editor): refuse Full Camera on a project that has no webcam

EtienneLescot742046aaeecb
diff --git a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
index 280853bef..f3a067bca 100644
--- a/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.geometry.test.tsx
@@ -63,14 +63,19 @@ function clip(startSec: number, endSec: number) {
};
}
+/** The asset every clip above points at. No `cameraTrack`: this recording has no webcam,
+ * which is what the Full Camera button is gated on. */
+const NO_CAMERA_ASSET = { id: "a1", label: "rec", durationSec: TOTAL_SEC };
+
/** By default one 30-minute clip carrying a single one-second annotation. */
function renderTimeline(
clips = [clip(0, TOTAL_SEC)],
annotation = { id: "ann1", startMs: 10_000, endMs: 11_000 },
+ assets: Array<Record<string, unknown>> = [NO_CAMERA_ASSET],
) {
const tl = {
clips,
- assets: [{ id: "a1", label: "rec", durationSec: TOTAL_SEC }],
+ assets,
annotationRegions: [annotation],
speedRegions: [],
cameraFullscreenRegions: [],
@@ -215,6 +220,46 @@ describe("V4Timeline create-from-toolbar", () => {
fireEvent.click(screen.getByTitle("buttons.addZoom"));
expect(durationOf(tl)).toBeCloseTo(0.25, 3);
});
+
+ // #353. A camera-fullscreen region grows the webcam overlay, so with no webcam on the
+ // timeline it renders nothing in the preview and nothing in the export — the region is
+ // stored and forgotten. `addCameraFullscreen` now refuses to write one; the button says
+ // so before it is clicked instead of looking like it worked.
+ it("disables Add Full Camera when no clip on the timeline has a camera", () => {
+ renderTimeline();
+ expect(screen.getByTitle("buttons.addCameraFullscreen")).toBeDisabled();
+ });
+
+ it("enables Add Full Camera as soon as a clip's asset carries one", () => {
+ renderTimeline(undefined, undefined, [
+ {
+ ...NO_CAMERA_ASSET,
+ cameraTrack: { sourcePath: "/tmp/cam.webm", startMs: 0, offsetMs: 0, visible: true },
+ },
+ ]);
+ expect(screen.getByTitle("buttons.addCameraFullscreen")).toBeEnabled();
+ });
+
+ // The disabled button is only half the promise: an empty lane advertises the shortcut
+ // that fills it, so on a camera-less project it was still inviting a `C` press that
+ // `addCameraFullscreen` now refuses. It borrows the Layout pane's "No Webcam" wording
+ // instead, so the two surfaces agree about the same project.
+ it("does not advertise the C shortcut on a lane that cannot be filled", () => {
+ renderTimeline();
+ expect(screen.getByText("layout.noWebcam")).toBeInTheDocument();
+ expect(screen.queryByText("hints.pressCameraFullscreen")).not.toBeInTheDocument();
+ });
+
+ it("advertises it again once a camera is on the timeline", () => {
+ renderTimeline(undefined, undefined, [
+ {
+ ...NO_CAMERA_ASSET,
+ cameraTrack: { sourcePath: "/tmp/cam.webm", startMs: 0, offsetMs: 0, visible: true },
+ },
+ ]);
+ expect(screen.getByText("hints.pressCameraFullscreen")).toBeInTheDocument();
+ expect(screen.queryByText("layout.noWebcam")).not.toBeInTheDocument();
+ });
});
describe("V4Timeline clip row", () => {
diff --git a/src/components/ai-edition/v4/V4Timeline.tsx b/src/components/ai-edition/v4/V4Timeline.tsx
index 0872d7f87..b6e5f34ea 100644
--- a/src/components/ai-edition/v4/V4Timeline.tsx
+++ b/src/components/ai-edition/v4/V4Timeline.tsx
@@ -39,6 +39,7 @@ import { useTimelineTranscriptGate } from "@/lib/ai-edition/store/transcriptionS
import { useChatPromptBus } from "@/lib/ai-edition/store/useChatPromptBus";
import { useEditorSettings } from "@/lib/ai-edition/store/useEditorSettings";
import type { useTimeline } from "@/lib/ai-edition/store/useTimeline";
+import { hasAnyClipWithCamera } from "@/lib/ai-edition/timeline/camera";
import { formatSec } from "@/lib/ai-edition/timeline/format";
import {
newRegionDurationSec,
@@ -396,6 +397,9 @@ export function V4Timeline({
onEditClip: (clip: AxcutClip) => void;
}) {
const t = useScopedT("timeline");
+ // The camera lane borrows the Layout pane's "No Webcam" wording when there is no
+ // camera to grow, so the two surfaces say the same thing about the same project.
+ const ts = useScopedT("settings");
const tracksRef = useRef<HTMLDivElement | null>(null);
// The transformed canvas is the true timeline coordinate frame — clips, pills
// and the playhead are all positioned inside it. Time↔x math must measure THIS
@@ -465,6 +469,12 @@ export function V4Timeline({
: t("toolbar.smartCutsNeedsTranscript");
const clips = tl.clips;
+ // A camera-fullscreen region grows the webcam overlay, so on a project with no webcam
+ // it renders nothing in the preview and nothing in the export. `addCameraFullscreen`
+ // refuses to write one (see useTimeline) — this makes the control say so before it is
+ // clicked instead of looking like it worked. Same question, same helper as the Layout
+ // pane: is a camera attached anywhere on this timeline?
+ const hasAnyCamera = useMemo(() => hasAnyClipWithCamera(tl.assets, clips), [tl.assets, clips]);
const total = useMemo(
() =>
Math.max(
@@ -1394,6 +1404,8 @@ export function V4Timeline({
className={styles.tlToolBtn}
title={t("buttons.addCameraFullscreen")}
aria-label={t("buttons.addCameraFullscreen")}
+ disabled={!hasAnyCamera}
+ style={!hasAnyCamera ? { opacity: 0.55, cursor: "not-allowed" } : undefined}
onClick={() => void tl.addCameraFullscreen(newRegionDurationSec())}
>
<Maximize2 size={15} />
@@ -1555,7 +1567,13 @@ export function V4Timeline({
<div className={styles.tlLane}>{renderPills(trimPills, t("hints.pressTrim"))}</div>
<div className={styles.tlLane}>{renderPills(zoomPills, t("hints.pressZoom"))}</div>
<div className={styles.tlLane}>
- {renderPills(cameraFullscreenPills, t("hints.pressCameraFullscreen"))}
+ {/* Advertising "Press C" on a project with no webcam invites a keystroke
+ that `addCameraFullscreen` now refuses (#353). The toolbar button is
+ already disabled; this keeps the lane from contradicting it. */}
+ {renderPills(
+ cameraFullscreenPills,
+ hasAnyCamera ? t("hints.pressCameraFullscreen") : ts("layout.noWebcam"),
+ )}
</div>
</>
) : null}
diff --git a/src/lib/ai-edition/store/useTimeline.test.ts b/src/lib/ai-edition/store/useTimeline.test.ts
index 5eeef2e32..939fc7c9d 100644
--- a/src/lib/ai-edition/store/useTimeline.test.ts
+++ b/src/lib/ai-edition/store/useTimeline.test.ts
@@ -479,6 +479,72 @@ describe("useTimeline.applyClipEdit (Edit-clip modal)", () => {
});
});
+// #353. The toolbar button and the `C` shortcut both used to write a region on a
+// project with no webcam: it persists into `legacyEditor.cameraFullscreenRegions`,
+// renders nothing in the preview (PreviewCanvas short-circuits on a missing
+// `webcamRect`) and nothing in the export, forever, with no feedback. The gate lives
+// in the shared mutation so both entry points — and any future one — are covered.
+describe("useTimeline.addCameraFullscreen (camera gate)", () => {
+ const cameraAsset = {
+ ...sampleDoc.assets[0],
+ cameraTrack: {
+ sourcePath: "/tmp/camera.webm",
+ startMs: 0,
+ offsetMs: 0,
+ visible: true,
+ // Dimensions filled in so the hook's backfill probe has nothing to do — an
+ // unprobed camera would fire its own `saveDocument` alongside this test's.
+ width: 1280,
+ height: 720,
+ },
+ };
+
+ beforeEach(() => {
+ useProjectStore.getState().clear();
+ for (const mock of Object.values(bridgeMocks)) mock.mockReset();
+ bridgeMocks.save.mockImplementation(async (doc: typeof sampleDoc) => ({
+ success: true,
+ document: doc,
+ }));
+ useProjectStore.setState({
+ projectId: "proj_test",
+ document: sampleDoc,
+ currentTimeSec: 1,
+ revision: 1,
+ status: "ready",
+ error: null,
+ });
+ });
+
+ afterEach(() => {
+ vi.clearAllMocks();
+ });
+
+ it("writes nothing when no clip on the timeline has a camera", async () => {
+ // sampleDoc's only asset carries `cameraTrack: null`.
+ const { result } = renderTimeline();
+ await act(async () => {
+ await result.current.addCameraFullscreen();
+ });
+ expect(bridgeMocks.save).not.toHaveBeenCalled();
+ expect(useProjectStore.getState().document?.legacyEditor).toBeNull();
+ expect(result.current.cameraFullscreenRegions).toEqual([]);
+ });
+
+ it("still writes a region when a clip's asset carries a camera", async () => {
+ useProjectStore.setState({ document: { ...sampleDoc, assets: [cameraAsset] } });
+ const { result } = renderTimeline();
+ await act(async () => {
+ await result.current.addCameraFullscreen();
+ });
+ const legacy = useProjectStore.getState().document?.legacyEditor as Record<string, unknown>;
+ const regions = legacy.cameraFullscreenRegions as Array<{ startMs: number; endMs: number }>;
+ expect(regions).toHaveLength(1);
+ // 2s at the playhead (currentTimeSec = 1), the shared default.
+ expect(regions[0]).toMatchObject({ startMs: 1000, endMs: 3000 });
+ });
+});
+
describe("useTimeline.addAnnotation", () => {
beforeEach(() => {
useProjectStore.getState().clear();
diff --git a/src/lib/ai-edition/store/useTimeline.ts b/src/lib/ai-edition/store/useTimeline.ts
index 11f3773b0..788a8a4fc 100644
--- a/src/lib/ai-edition/store/useTimeline.ts
+++ b/src/lib/ai-edition/store/useTimeline.ts
@@ -20,6 +20,7 @@ import {
setClipSourceRange,
} from "../document/timeline";
import type { AxcutClipCropRegion, AxcutDocument } from "../schema";
+import { hasAnyClipWithCamera } from "../timeline/camera";
import { probeVideoDimensions, probeVideoDuration } from "../timeline/duration";
import {
anchorRegionsWithDerivedMs,
@@ -394,9 +395,20 @@ export function useTimeline() {
// Full Camera: a plain time span (no value) during which the preview/export
// grows the webcam overlay to (almost) fill the canvas and eases it back.
+ //
+ // With no webcam anywhere on the timeline there is nothing to grow, so the region
+ // renders nothing in the preview (`PreviewCanvas.effectiveLayout` short-circuits on
+ // a missing `webcamRect`) and nothing in the export — it just sits in
+ // `legacyEditor.cameraFullscreenRegions` forever. The agent's `addCameraFullscreen`
+ // tool already refuses this and says why (electron/ai-edition/agent-tools.ts,
+ // `noCameraUnderSpan`); the gate lives HERE rather than at each button so both UI
+ // entry points — the toolbar and the `C` shortcut — and any future one are covered
+ // by construction. `hasAnyClipWithCamera` is the consolidated answer to "does this
+ // project have a camera at all", used the same way by the Layout pane.
const addCameraFullscreen = useCallback(
async (durationSec = DEFAULT_NEW_REGION_SEC) => {
if (!document) return;
+ if (!hasAnyClipWithCamera(document.assets, document.timeline.clips)) return;
const timeMs = Math.round(playheadSec() * 1000);
const endMs = timeMs + Math.round(durationSec * 1000);
const legacy = (document.legacyEditor as Record<string, unknown>) ?? {};