Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix: the four CodeRabbit findings that were left, including the read capability
EtienneLescot8fb74f9aed73
diff --git a/crates/compositor/src/audio.rs b/crates/compositor/src/audio.rsindex 6d7c8d4ec..ee90c1374 100644--- a/crates/compositor/src/audio.rs+++ b/crates/compositor/src/audio.rs@@ -1424,6 +1424,11 @@ pub fn mix_external_tracks(mut programme: PlanarPcm, tracks: &[SceneAudioTrack])// second 9 of a ten-second export must not buffer three hours of PCM.let remaining_sec = (programme_len - offset) as f64 / AUDIO_OUTPUT_SAMPLE_RATE as f64;let trim_end = trim_end_full.min(trim_start + remaining_sec);+ // The track's own length, before that cap. The fades belong to the track, not to+ // whatever the programme had room for — capping first and measuring after is what+ // made a fade-out ramp down at the truncation point instead of at the real end.+ let full_len =+ ((trim_end_full - trim_start).max(0.0) * AUDIO_OUTPUT_SAMPLE_RATE as f64) as usize;if trim_end <= trim_start {continue;}@@ -1441,6 +1446,7 @@ pub fn mix_external_tracks(mut programme: PlanarPcm, tracks: &[SceneAudioTrack])gain,track.fade_in_sec.max(0.0),track.fade_out_sec.max(0.0),+ full_len,);}programme@@ -1457,6 +1463,10 @@ fn overlay_track_pcm(gain: f32,fade_in_sec: f64,fade_out_sec: f64,+ // The track's length before the programme cap, in samples, or 0 when nothing capped it.+ // `decoded` may be shorter because the decode window was capped at the room left in the+ // programme; the ramps belong to the track, not to the room.+ full_len: usize,) {let programme_len = programme.first().map(Vec::len).unwrap_or(0);if offset >= programme_len {@@ -1467,7 +1477,8 @@ fn overlay_track_pcm(// programme: a track running past the end is cut off there, and a fade-out// timed to the cut would ramp down over audio the export never reaches.let decoded_len = decoded.iter().map(Vec::len).max().unwrap_or(0);- let (fade_in, fade_out) = resolve_fade_samples(decoded_len, fade_in_sec, fade_out_sec);+ let envelope_len = full_len.max(decoded_len);+ let (fade_in, fade_out) = resolve_fade_samples(envelope_len, fade_in_sec, fade_out_sec);for channel in 0..AUDIO_OUTPUT_CHANNELS {let Some(source) = decoded.get(channel) else {continue;@@ -1475,7 +1486,7 @@ fn overlay_track_pcm(let count = source.len().min(room);let dst = &mut programme[channel];for k in 0..count {- dst[offset + k] += source[k] * gain * fade_envelope(k, decoded_len, fade_in, fade_out);+ dst[offset + k] += source[k] * gain * fade_envelope(k, envelope_len, fade_in, fade_out);}}}@@ -1867,7 +1878,7 @@ mod tests {fn overlay_sums_at_offset_with_gain() {let mut programme = planar(&[0.1, 0.1, 0.1, 0.1]);// ×2 gain, placed at sample offset 1.- overlay_track_pcm(&mut programme, &planar(&[0.2, 0.2]), 1, 2.0, 0.0, 0.0);+ overlay_track_pcm(&mut programme, &planar(&[0.2, 0.2]), 1, 2.0, 0.0, 0.0, 0);assert_eq!(programme[0], vec![0.1, 0.5, 0.5, 0.1]);assert_eq!(programme[1], vec![0.1, 0.5, 0.5, 0.1]);}@@ -1876,14 +1887,14 @@ mod tests {fn overlay_truncates_a_track_that_runs_past_the_programme() {let mut programme = planar(&[0.0, 0.0, 0.0]);// A 4-sample track placed at offset 2 has room for only 1 sample.- overlay_track_pcm(&mut programme, &planar(&[1.0, 1.0, 1.0, 1.0]), 2, 1.0, 0.0, 0.0);+ overlay_track_pcm(&mut programme, &planar(&[1.0, 1.0, 1.0, 1.0]), 2, 1.0, 0.0, 0.0, 0);assert_eq!(programme[0], vec![0.0, 0.0, 1.0]);}#[test]fn overlay_past_the_end_is_a_no_op() {let mut programme = planar(&[0.3, 0.3]);- overlay_track_pcm(&mut programme, &planar(&[1.0]), 5, 1.0, 0.0, 0.0);+ overlay_track_pcm(&mut programme, &planar(&[1.0]), 5, 1.0, 0.0, 0.0, 0);assert_eq!(programme[0], vec![0.3, 0.3]);}@@ -2064,12 +2075,30 @@ mod tests {// A 4-sample fade-in at 48 kHz is far below one sample of real time, so// ask for the whole decoded length in seconds.let four = 4.0 / AUDIO_OUTPUT_SAMPLE_RATE as f64;- overlay_track_pcm(&mut programme, &decoded, 0, 1.0, four, 0.0);+ overlay_track_pcm(&mut programme, &decoded, 0, 1.0, four, 0.0, 0);assert_eq!(programme[0][0], 0.0);assert!(programme[0][1] > 0.0 && programme[0][1] < 1.0);assert!(programme[0][3] > programme[0][1]);}+ #[test]+ fn a_capped_track_keeps_its_fade_out_at_its_real_end() {+ // The decode window is capped at the room left in the programme, so `decoded` is+ // SHORTER than the track. Measuring the ramp against what came back would put the+ // fade-out at the truncation point — the export would hear a track fading out that+ // is in fact being cut off mid-sentence.+ let mut programme = planar(&[0.0, 0.0, 0.0, 0.0]);+ let decoded = planar(&[1.0, 1.0, 1.0, 1.0]);+ let four = 4.0 / AUDIO_OUTPUT_SAMPLE_RATE as f64;+ // The track really runs eight samples; the programme had room for four.+ overlay_track_pcm(&mut programme, &decoded, 0, 1.0, 0.0, four, 8);+ // Nothing audible has started to ramp: the fade belongs to samples 4..8, which the+ // programme never reaches.+ for k in 0..4 {+ assert_eq!(programme[0][k], 1.0, "sample {k} should be untouched");+ }+ }+#[test]fn a_track_gain_below_the_output_bound_is_honoured() {// The per-track gain range is the inspector's -60..+12, NOT the project@@ -2078,7 +2107,7 @@ mod tests {let mut programme = planar(&[0.0]);let decoded = planar(&[1.0]);let gain = 10.0f32.powf(-40.0 / 20.0);- overlay_track_pcm(&mut programme, &decoded, 0, gain, 0.0, 0.0);+ overlay_track_pcm(&mut programme, &decoded, 0, gain, 0.0, 0.0, 0);assert!((programme[0][0] - gain).abs() < 1e-9);assert!(programme[0][0] < 10.0f32.powf(-12.0 / 20.0));}diff --git a/electron/ai-edition/document-service.test.ts b/electron/ai-edition/document-service.test.tsindex bf3d12289..5951c9090 100644--- a/electron/ai-edition/document-service.test.ts+++ b/electron/ai-edition/document-service.test.ts@@ -245,6 +245,34 @@ describe("DocumentService", () => {});});+ describe("onProjectRead", () => {+ it("announces every document it hands out, after the relink", async () => {+ // The read allow-list lives in the main process and is in memory: a picker's+ // approval is gone by the next launch. This callback is how a project reopened+ // tomorrow can still read the media it declares — and it must fire with the+ // RELINKED paths, since those are the ones the renderer will ask for.+ const seen: string[][] = [];+ const service = new DocumentService(tempDir, mediaDir, (doc) =>+ seen.push(doc.assets.map((a) => a.originalPath)),+ );+ const created = await service.createProject("P");+ const withAsset = await service.addAsset(created.project.id, {+ path: path.join(mediaDir, "take.mp4"),+ label: "take.mp4",+ });+ seen.length = 0;+ await service.getProject(created.project.id);+ expect(seen).toEqual([withAsset.assets.map((a) => a.originalPath)]);+ });++ it("is optional, so a service built without it loads as it always did", async () => {+ const created = await service.createProject("P");+ await expect(service.getProject(created.project.id)).resolves.toMatchObject({+ project: { id: created.project.id },+ });+ });+ });+describe("addAsset", () => {it("appends a video asset and sets primaryAssetId on the first add", async () => {const doc = await service.createProject("P");diff --git a/electron/ai-edition/document-service.ts b/electron/ai-edition/document-service.tsindex 2fca7962c..e78a9c48e 100644--- a/electron/ai-edition/document-service.ts+++ b/electron/ai-edition/document-service.ts@@ -157,9 +157,23 @@ export class DocumentService {// `mediaRegistryDir` is where the media-links registry file lives// (RECORDINGS_DIR in production) — see getProject. Injected for the same// reason as `projectsRoot`: this module stays free of any `electron` import.- constructor(projectsRoot: string, mediaRegistryDir: string) {+ /**+ * Called with every document this service hands out, so the process that owns the read+ * allow-list can grant the media that document declares.+ *+ * Injected for the same reason as the two paths above: this module stays free of any+ * `electron` import. Optional so the tests and the CLI construct it as they always did.+ */+ private readonly onProjectRead?: (document: AxcutDocument) => void;++ constructor(+ projectsRoot: string,+ mediaRegistryDir: string,+ onProjectRead?: (document: AxcutDocument) => void,+ ) {this.projectsRoot = projectsRoot;this.mediaRegistryDir = mediaRegistryDir;+ this.onProjectRead = onProjectRead;}async ensureProjectsDir(): Promise<void> {@@ -274,7 +288,12 @@ export class DocumentService {// back, and it is not persisted from here: the renderer saves the document// it was given, as it does for any other load-time repair.const migrated = migrateRawDocumentToCurrent(JSON.parse(raw));- return documentSchema.parse(await relinkProjectMedia(migrated, this.mediaRegistryDir));+ const document = documentSchema.parse(+ await relinkProjectMedia(migrated, this.mediaRegistryDir),+ );+ // AFTER the relink, so what is granted is the path the renderer will actually ask for.+ this.onProjectRead?.(document);+ return document;}async createProject(title: string): Promise<AxcutDocument> {diff --git a/electron/ipc/handlers.ts b/electron/ipc/handlers.tsindex f404daa84..fcda39e0c 100644--- a/electron/ipc/handlers.ts+++ b/electron/ipc/handlers.ts@@ -16,6 +16,7 @@ import {shell,systemPreferences,} from "electron";+import type { AxcutDocument } from "../../src/lib/ai-edition/schema";import {type NativeLinuxRecordingRequest,portalCursorMode,@@ -372,13 +373,37 @@ function approveReadableAudioPath(return approveReadableMediaPath(filePath, hasAllowedImportAudioExtension, trustedDirs);}-// For the generic media reads that accept either kind — NOT for the pickers,-// which must stay type-specific (see `hasAllowedImportMediaExtension`).-function approveReadableAvPath(- filePath?: string | null,- trustedDirs?: string[],-): Promise<string | null> {- return approveReadableMediaPath(filePath, hasAllowedImportMediaExtension, trustedDirs);+/**+ * A path a generic read may use — and NOT a way to obtain one.+ *+ * `approveReadableMediaPath` grants approval to any existing file with a media extension.+ * Behind a picker or a document load that is the point; behind `read-binary-file` it meant+ * the renderer could name any media file on the machine and have its bytes handed back,+ * which is a capability no generic handler should carry (CWE-200).+ *+ * Approval is granted in exactly three places now: the recordings directory, a file the user+ * picked, and the assets a loaded project declares (`approveDocumentMedia`). Everything else+ * spends one.+ */+function readableApprovedPath(filePath?: string | null): string | null {+ const normalizedPath = normalizeVideoSourcePath(filePath);+ if (!normalizedPath) return null;+ if (!isPathAllowed(normalizedPath)) return null;+ // The extension check stays: an approval granted for a recording must not become a way+ // to read the project file, the log, or anything else sitting beside it.+ if (!hasAllowedImportMediaExtension(normalizedPath)) return null;+ return normalizedPath;+}++/** Grant the media a loaded project declares. The document is the app's own file, and this+ * is what the picker's approval decays into once the app restarts. */+function approveDocumentMedia(document: AxcutDocument): void {+ for (const asset of document.assets ?? []) {+ const media = normalizeVideoSourcePath(asset.originalPath);+ if (media && hasAllowedImportMediaExtension(media)) approveFilePath(media);+ const camera = normalizeVideoSourcePath(asset.cameraTrack?.sourcePath);+ if (camera && hasAllowedImportMediaExtension(camera)) approveFilePath(camera);+ }}function resolveRecordingOutputPath(fileName: string): string {@@ -3800,7 +3825,7 @@ export function registerIpcHandlers(ipcMain.handle("read-binary-file", async (_, filePath: string) => {try {- const normalizedPath = await approveReadableAvPath(filePath);+ const normalizedPath = readableApprovedPath(filePath);if (!normalizedPath) {return {success: false,@@ -3830,7 +3855,7 @@ export function registerIpcHandlers(// recording above that can never be loaded whole — see read-file-chunk).ipcMain.handle("get-readable-file-info", async (_, filePath: string) => {try {- const normalizedPath = await approveReadableAvPath(filePath);+ const normalizedPath = readableApprovedPath(filePath);if (!normalizedPath) {return {success: false,@@ -3866,7 +3891,7 @@ export function registerIpcHandlers(async (_, filePath: string, durationSec: number): Promise<AudioPeaksResult> => {try {// Same approval gate as every other read of a renderer-supplied path.- const normalizedPath = await approveReadableAvPath(filePath);+ const normalizedPath = readableApprovedPath(filePath);if (!normalizedPath) {return { success: false, message: "File path is not approved" };}@@ -3890,7 +3915,7 @@ export function registerIpcHandlers(// do (2 GiB cap) and a 16 GB machine cannot hold for multi-GB recordings.ipcMain.handle("read-file-chunk", async (_, filePath: string, offset: number, length: number) => {try {- const normalizedPath = await approveReadableAvPath(filePath);+ const normalizedPath = readableApprovedPath(filePath);if (!normalizedPath) {return {success: false,@@ -4319,6 +4344,7 @@ export function registerIpcHandlers(const aiEditionDocuments = new DocumentService(path.join(app.getPath("userData"), "projects"),RECORDINGS_DIR,+ approveDocumentMedia,);// LlmConfigStore is single-instance for a duller reason — its constructor doesdiff --git a/electron/stt/index.ts b/electron/stt/index.tsindex 1004726f5..a20f4e577 100644--- a/electron/stt/index.ts+++ b/electron/stt/index.ts@@ -104,6 +104,13 @@ export class SttManager {*/private cancelEpoch = 0;+ /**+ * The extraction in flight, if any. `cancelEpoch` alone stops the CHUNK loop, which is+ * checked between chunks — so a cancel during the decode left ffmpeg running to+ * completion on a file that can be hours long, and the user saw nothing stop.+ */+ private extraction: AbortController | null = null;+/*** Attach a sink for the renderer status channel; returns its detach function.*@@ -135,6 +142,7 @@ export class SttManager {*/cancel(): void {this.cancelEpoch++;+ this.extraction?.abort();}/**@@ -243,7 +251,15 @@ export class SttManager {if (!req.sourcePath) {throw new Error("stt:transcribe needs either `samples` or `sourcePath`");}- return extractMono16kPcm(req.sourcePath);+ const controller = new AbortController();+ this.extraction = controller;+ try {+ return await extractMono16kPcm(req.sourcePath, { signal: controller.signal });+ } finally {+ // Only if it is still ours: a cancel that started a new run must not have its+ // controller cleared by the old one unwinding.+ if (this.extraction === controller) this.extraction = null;+ }}async transcribe(req: SttTranscribeRequest): Promise<SttTranscribeResponse> {diff --git a/src/components/ui/tooltip.tsx b/src/components/ui/tooltip.tsxindex 823b3f9b5..5ca6071ac 100644--- a/src/components/ui/tooltip.tsx+++ b/src/components/ui/tooltip.tsx@@ -20,9 +20,16 @@ function TooltipRoot({ ...props }: React.ComponentProps<typeof TooltipPrimitive.return <TooltipPrimitive.Root data-slot="tooltip" {...props} />;}-function TooltipTrigger({ ...props }: React.ComponentProps<typeof TooltipPrimitive.Trigger>) {- return <TooltipPrimitive.Trigger data-slot="tooltip-trigger" {...props} />;-}+// forwardRef, like PopoverTrigger: `Tooltip` below hands its own ref here, and on React 18+// a plain function component drops it silently — the ref resolves to null and React logs+// "Function components cannot be given refs".+const TooltipTrigger = React.forwardRef<+ React.ComponentRef<typeof TooltipPrimitive.Trigger>,+ React.ComponentProps<typeof TooltipPrimitive.Trigger>+>(({ ...props }, ref) => (+ <TooltipPrimitive.Trigger ref={ref} data-slot="tooltip-trigger" {...props} />+));+TooltipTrigger.displayName = "TooltipTrigger";function TooltipContent({className,