From 30dfeb7f4539b61b49c9e2f11e5c4f9b6dda9b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=AA=E6=88=90=E7=86=9F=E7=9A=84=E5=89=AA?= =?UTF-8?q?=E8=BE=91=E7=8C=BF?= <297668904+akahoz94@users.noreply.github.com> Date: Wed, 4 Nov 2026 08:30:03 +0800 Subject: [PATCH 1/2] feat(recording): show the countdown and a marquee on the display being recorded The countdown overlay was bounded to the primary display (screen.getPrimaryDisplay()), so on a multi-screen setup the 3-2-1 always played on the wrong screen and the user could not tell which display the take would capture. - countdown-overlay-show now bounds the overlay to the selected source's display (or the window rect, for window takes), reusing getSelectedSourceBounds. - After the last digit, a one-shot ring sweeps the recorded display before the hide (countdown-overlay-marquee): it resolves only once the sweep has faded, and the capture arms after the ordinary hide, so the ring cannot reach the video and no content protection is needed. The Linux clear-frame ordering is untouched. - The overlay window drops its fixed 420x260 clamps so it can cover a display; the digit stays CSS-centered. Tests: vitest CountdownOverlay.test.tsx (4 passed, 2 new cases); tsc --noEmit clean for both tsconfig.json and tsconfig.node.json; biome check clean on changed files. --- electron/countdownOverlay.ts | 8 +++ electron/electron-env.d.ts | 3 + electron/ipc/handlers.ts | 25 +++++++- electron/preload.ts | 8 +++ electron/windows.ts | 13 ++--- .../launch/CountdownOverlay.test.tsx | 28 +++++++++ src/components/launch/CountdownOverlay.tsx | 40 +++++++++---- src/hooks/useScreenRecorder.ts | 22 +++++++ src/index.css | 58 +++++++++++++++++++ 9 files changed, 185 insertions(+), 20 deletions(-) diff --git a/electron/countdownOverlay.ts b/electron/countdownOverlay.ts index 6ddf160645..2a8d473877 100644 --- a/electron/countdownOverlay.ts +++ b/electron/countdownOverlay.ts @@ -16,6 +16,14 @@ /** Sent by the overlay's renderer once a frame without the digit has been painted. */ export const COUNTDOWN_OVERLAY_CLEARED_CHANNEL = "countdown-overlay-cleared"; +/** + * How long the post-countdown marquee sweeps the recorded display before the take starts: + * the CSS animation on the overlay's ring runs ~1.3 s, this gives it the fade-out margin. + * The marquee plays while the capture is not armed yet, so it cannot leak into the video — + * the window is still hidden (and on Linux, clear-frame ordered) before the first frame. + */ +export const RECORDING_MARQUEE_MS = 1_400; + /** * How long to wait for that report before hiding anyway. A cleared frame normally takes a few * display frames; this only bounds a renderer that never answers, which would otherwise keep diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.ts index f0c93ff955..e8eb89fb3d 100644 --- a/electron/electron-env.d.ts +++ b/electron/electron-env.d.ts @@ -548,6 +548,9 @@ interface Window { showCountdownOverlay: (value: number, runId: number) => Promise; setCountdownOverlayValue: (value: number, runId: number) => Promise; hideCountdownOverlay: (runId: number) => Promise; + /** Resolves after the one-shot marquee has swept the recorded display. */ + runRecordingMarquee: (runId: number) => Promise; + onCountdownOverlayMarquee: (callback: (runId: number) => void) => () => void; onCountdownOverlayValue: ( callback: (value: number | null, runId: number) => void, ) => () => void; diff --git a/electron/ipc/handlers.ts b/electron/ipc/handlers.ts index e4bab0f5cb..8af2f7ffe4 100644 --- a/electron/ipc/handlers.ts +++ b/electron/ipc/handlers.ts @@ -77,7 +77,7 @@ import { writeFileReplacing } from "../atomic-rename"; import { bringToFront } from "../bringToFront"; import { CameraPreviewController } from "../cameraPreview"; import { createRunnerHost } from "../cli/runnerHost"; -import { hideCountdownOverlay } from "../countdownOverlay"; +import { hideCountdownOverlay, RECORDING_MARQUEE_MS } from "../countdownOverlay"; import { isDiagnosticModeEnabled, mainLogFile } from "../diagnostics/main-log-file"; import { createZip } from "../diagnostics/zip"; import { mainT } from "../i18n"; @@ -2670,6 +2670,13 @@ export function registerIpcHandlers( return; } + // Bound the overlay to the source the take will capture, so the countdown + // digit (and the marquee after it) land on the recorded display instead of + // the primary one — multi-screen users otherwise read the countdown on the + // wrong screen. A display pick resolves to the display's bounds; a window + // pick to that window's rect, via `getSelectedSourceBounds`. + overlayWindow.setBounds(getSelectedSourceBounds()); + // Wait for the first frame before showing, else Chromium flashes a black // rectangle because it hasn't rendered any pixels yet. if (overlayWindow.webContents.isLoading()) { @@ -2709,6 +2716,22 @@ export function registerIpcHandlers( }); }); + // The one-shot marquee after the last countdown digit: the overlay sweeps a + // ring around the display it is already bounded to, then the take starts. + // Resolving after the sweep is what gates the capture: the ring plays while + // the capture is not armed yet, so it cannot leak into the video, and the + // ordinary hide (clear-frame ordered on Linux, see `countdownOverlay.ts`) + // still runs before the first frame. + ipcMain.handle("countdown-overlay-marquee", async (_, runId: number) => { + const overlayWindow = getCountdownOverlayWindow?.(); + if (!overlayWindow || overlayWindow.isDestroyed()) { + return; + } + + overlayWindow.webContents.send("countdown-overlay-marquee", runId); + await new Promise((resolve) => setTimeout(resolve, RECORDING_MARQUEE_MS)); + }); + ipcMain.handle("is-native-windows-capture-available", async () => { if (!isWindowsGraphicsCaptureOsSupported()) { return { success: true, available: false, reason: "unsupported-os" }; diff --git a/electron/preload.ts b/electron/preload.ts index 3f5716036d..72c4d49fce 100644 --- a/electron/preload.ts +++ b/electron/preload.ts @@ -612,6 +612,14 @@ contextBridge.exposeInMainWorld("electronAPI", { hideCountdownOverlay: (runId: number) => { return ipcRenderer.invoke("countdown-overlay-hide", runId); }, + runRecordingMarquee: (runId: number) => { + return ipcRenderer.invoke("countdown-overlay-marquee", runId); + }, + onCountdownOverlayMarquee: (callback: (runId: number) => void) => { + const listener = (_event: unknown, runId: number) => callback(runId); + ipcRenderer.on("countdown-overlay-marquee", listener); + return () => ipcRenderer.removeListener("countdown-overlay-marquee", listener); + }, onCountdownOverlayValue: (callback: (value: number | null, runId: number) => void) => { const listener = (_event: unknown, value: number | null, runId: number) => callback(value, runId); diff --git a/electron/windows.ts b/electron/windows.ts index 386e256cce..41907ab6e1 100644 --- a/electron/windows.ts +++ b/electron/windows.ts @@ -800,23 +800,18 @@ export function createSourceSelectorWindow(): BrowserWindow { } /** - * Centered transparent countdown overlay that sits above the HUD during - * recording pre-roll. + * Transparent countdown overlay that sits above the HUD during recording + * pre-roll. It has no fixed size: the show handler (`ipc/handlers.ts`) bounds it + * to the display being recorded, so the countdown digit and the marquee ring + * land on the screen the take will capture, not on the primary one. */ export function createCountdownOverlayWindow(): BrowserWindow { - const { workArea } = screen.getPrimaryDisplay(); const overlayWidth = 420; const overlayHeight = 260; const win = new BrowserWindow({ width: overlayWidth, height: overlayHeight, - minWidth: overlayWidth, - maxWidth: overlayWidth, - minHeight: overlayHeight, - maxHeight: overlayHeight, - x: Math.round(workArea.x + (workArea.width - overlayWidth) / 2), - y: Math.round(workArea.y + (workArea.height - overlayHeight) / 2), frame: false, resizable: false, alwaysOnTop: true, diff --git a/src/components/launch/CountdownOverlay.test.tsx b/src/components/launch/CountdownOverlay.test.tsx index 621bab7bb9..dca385a0a8 100644 --- a/src/components/launch/CountdownOverlay.test.tsx +++ b/src/components/launch/CountdownOverlay.test.tsx @@ -4,9 +4,11 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { CLEARED_AFTER_FRAMES, CountdownOverlay } from "./CountdownOverlay"; type ValueListener = (value: number | null, runId: number) => void; +type MarqueeListener = (runId: number) => void; describe("CountdownOverlay", () => { let pushValue: ValueListener = () => undefined; + let pushMarquee: MarqueeListener = () => undefined; let frames: FrameRequestCallback[] = []; let textAtFrameRequest: string[] = []; let notifyCleared: ReturnType; @@ -27,6 +29,10 @@ describe("CountdownOverlay", () => { pushValue = listener; return () => undefined; }, + onCountdownOverlayMarquee: (listener: MarqueeListener) => { + pushMarquee = listener; + return () => undefined; + }, notifyCountdownOverlayCleared: notifyCleared, } as typeof window.electronAPI; ({ container } = render()); @@ -70,4 +76,26 @@ describe("CountdownOverlay", () => { expect(frames).toHaveLength(0); expect(notifyCleared).not.toHaveBeenCalled(); }); + + it("replaces the digit with the marquee ring on the marquee event", () => { + act(() => pushValue(1, 7)); + expect(container.querySelector(".recording-marquee-ring")).toBeNull(); + + act(() => pushMarquee(7)); + + // The ring is up and the digit is gone — the sweep plays between the countdown + // and the take, so the digit must not linger under it. + expect(container.querySelector(".recording-marquee-ring")).not.toBeNull(); + expect(container.textContent).toBe(""); + }); + + it("drops the ring when the next countdown digit arrives", () => { + act(() => pushMarquee(3)); + expect(container.querySelector(".recording-marquee-ring")).not.toBeNull(); + + act(() => pushValue(3, 3)); + + expect(container.querySelector(".recording-marquee-ring")).toBeNull(); + expect(container.textContent).toBe("3"); + }); }); diff --git a/src/components/launch/CountdownOverlay.tsx b/src/components/launch/CountdownOverlay.tsx index 6b5071b722..91afa6e2e1 100644 --- a/src/components/launch/CountdownOverlay.tsx +++ b/src/components/launch/CountdownOverlay.tsx @@ -19,11 +19,18 @@ function afterAnimationFrames(count: number, callback: () => void) { export function CountdownOverlay() { const [value, setValue] = useState(null); + /** The one-shot ring that sweeps the display between the last digit and the take. */ + const [marquee, setMarquee] = useState(false); useEffect(() => { const unsubscribe = window.electronAPI.onCountdownOverlayValue((nextValue, runId) => { // Committed now rather than batched, so every frame counted below is already empty. flushSync(() => setValue(nextValue)); + // A digit replaces the ring: a cancelled marquee, or the next countdown, must not + // leave the previous run's sweep behind. + if (nextValue !== null) { + setMarquee(false); + } if (nextValue === null) { afterAnimationFrames(CLEARED_AFTER_FRAMES, () => window.electronAPI.notifyCountdownOverlayCleared(runId), @@ -31,23 +38,36 @@ export function CountdownOverlay() { } }); - return () => unsubscribe(); + const unsubscribeMarquee = window.electronAPI.onCountdownOverlayMarquee(() => { + setMarquee(true); + }); + + return () => { + unsubscribe(); + unsubscribeMarquee(); + }; }, []); - if (value === null) { + if (value === null && !marquee) { return null; } return (
-
-
- {value} -
-
+ {marquee ? ( + ); } diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.ts index f4ef513918..cd64f3faa9 100644 --- a/src/hooks/useScreenRecorder.ts +++ b/src/hooks/useScreenRecorder.ts @@ -1261,6 +1261,16 @@ export function useScreenRecorder(): UseScreenRecorderReturn { } }; + // Best-effort like every overlay call: a marquee that fails to play must not fail the + // take — the hide below still runs, and recording starts as it always did. + const safeRunRecordingMarquee = async (runId: number) => { + try { + await window.electronAPI.runRecordingMarquee(runId); + } catch (error) { + console.warn("Failed to play the recording marquee:", error); + } + }; + const isCountdownRunActive = (runId?: number) => runId === undefined || countdownRunId.current === runId; @@ -1928,6 +1938,18 @@ export function useScreenRecorder(): UseScreenRecorderReturn { return; } + // After the last digit, the marquee sweeps the display about to be recorded — + // the user's cue for which screen the take lands on. It resolves once the sweep + // has faded; the capture arms only after the hide below, so the ring cannot + // reach the video. + if (overlayShown) { + await safeRunRecordingMarquee(runId); + + if (countdownRunId.current !== runId) { + return; + } + } + setCountdownActive(false); await safeHideCountdownOverlay(runId); overlayHiddenBeforeStart = true; diff --git a/src/index.css b/src/index.css index 2a92cfc263..7483e2009b 100644 --- a/src/index.css +++ b/src/index.css @@ -397,3 +397,61 @@ html [data-sonner-toaster] [data-sonner-toast][data-styled="true"] [data-close-b background: color-mix(in oklab, var(--fg) 10%, transparent); color: var(--fg); } + +/* The recording marquee: a ring that sweeps the display about to be recorded, between the + countdown and the first captured frame (`CountdownOverlay.tsx`, `countdown-overlay-marquee` + in `ipc/handlers.ts`). The window covers the whole display, so the ring traces its edges; + the rotating gradient lives on an oversized ::before, clipped to a ring by the padding-box + mask, so the sweep stays a moving highlight instead of a spinning pie. It plays once and + fades — the capture is not armed yet, nothing here can leak into the video. */ +@keyframes recording-marquee-sweep { + from { + transform: rotate(0turn); + } + to { + transform: rotate(1.5turn); + } +} + +@keyframes recording-marquee-fade { + 0%, + 75% { + opacity: 1; + } + 100% { + opacity: 0; + } +} + +.recording-marquee-ring { + position: absolute; + inset: 0; + overflow: hidden; + border-radius: 24px; + padding: 6px; + animation: recording-marquee-fade 1.3s ease-out 1 both; + -webkit-mask: + linear-gradient(#fff 0 0) content-box, + linear-gradient(#fff 0 0); + -webkit-mask-composite: xor; + mask: + linear-gradient(#fff 0 0) content-box, + linear-gradient(#fff 0 0); + mask-composite: exclude; +} + +.recording-marquee-ring::before { + content: ""; + position: absolute; + inset: -60%; + background: conic-gradient( + from 0deg, + transparent 0deg, + #38bdf8 90deg, + #a5f3fc 160deg, + #38bdf8 230deg, + transparent 320deg, + transparent 360deg + ); + animation: recording-marquee-sweep 1.2s cubic-bezier(0.4, 0, 0.2, 1) 1 both; +} From 93468653305431a6b98f097f14a622c3c037a6f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=80=E4=B8=AA=E6=88=90=E7=86=9F=E7=9A=84=E5=89=AA?= =?UTF-8?q?=E8=BE=91=E7=8C=BF?= <297668904+akahoz94@users.noreply.github.com> Date: Fri, 20 Nov 2026 05:42:47 +0800 Subject: [PATCH 2/2] fix(countdown): clear the marquee in the same frame as the cleared acknowledgement On Linux the overlay hide waits for the cleared frame before the capture arms. If the ring was still painted when that frame was acknowledged, the hide could carry it into the take. Clear the ring in the same flushSync commit as the null value, and cover it with a test that asserts no ring survives into the counted frames. --- .../launch/CountdownOverlay.test.tsx | 19 +++++++++++++++++++ src/components/launch/CountdownOverlay.tsx | 11 ++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/components/launch/CountdownOverlay.test.tsx b/src/components/launch/CountdownOverlay.test.tsx index dca385a0a8..dced171e99 100644 --- a/src/components/launch/CountdownOverlay.test.tsx +++ b/src/components/launch/CountdownOverlay.test.tsx @@ -98,4 +98,23 @@ describe("CountdownOverlay", () => { expect(container.querySelector(".recording-marquee-ring")).toBeNull(); expect(container.textContent).toBe("3"); }); + + it("clears the ring in the same commit as the cleared frame", () => { + act(() => pushMarquee(5)); + expect(container.querySelector(".recording-marquee-ring")).not.toBeNull(); + + act(() => pushValue(null, 5)); + + // The ring is gone before the first frame is even requested: a cleared frame that + // still painted the ring would let the hide carry it into the take on Linux. + expect(container.querySelector(".recording-marquee-ring")).toBeNull(); + expect(textAtFrameRequest[0]).toBe(""); + for (let frame = 1; frame < CLEARED_AFTER_FRAMES; frame += 1) { + nextFrame(); + expect(container.querySelector(".recording-marquee-ring")).toBeNull(); + expect(notifyCleared).not.toHaveBeenCalled(); + } + nextFrame(); + expect(notifyCleared).toHaveBeenCalledExactlyOnceWith(5); + }); }); diff --git a/src/components/launch/CountdownOverlay.tsx b/src/components/launch/CountdownOverlay.tsx index 91afa6e2e1..a915983685 100644 --- a/src/components/launch/CountdownOverlay.tsx +++ b/src/components/launch/CountdownOverlay.tsx @@ -25,12 +25,13 @@ export function CountdownOverlay() { useEffect(() => { const unsubscribe = window.electronAPI.onCountdownOverlayValue((nextValue, runId) => { // Committed now rather than batched, so every frame counted below is already empty. - flushSync(() => setValue(nextValue)); - // A digit replaces the ring: a cancelled marquee, or the next countdown, must not - // leave the previous run's sweep behind. - if (nextValue !== null) { + // The ring clears in the same commit as the digit OR the cleared frame: a null value + // must not leave the previous run's sweep still painted when the cleared frame is + // acknowledged, or the hide can carry that ring into the take on Linux. + flushSync(() => { + setValue(nextValue); setMarquee(false); - } + }); if (nextValue === null) { afterAnimationFrames(CLEARED_AFTER_FRAMES, () => window.electronAPI.notifyCountdownOverlayCleared(runId),