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(recording): refuse to start a take on a nearly full disk
abduznik4e0b40cb60c2
diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.tsindex 26f2f5308..1466c5139 100644--- a/electron/electron-env.d.ts+++ b/electron/electron-env.d.ts@@ -457,6 +457,8 @@ interface Window {revealInFolder: (filePath: string,) => Promise<{ success: boolean; error?: string; message?: string }>;+ /** Whether a take can start: refused, with the message to show, when the disk is nearly full. */+ checkRecordingStorage: () => Promise<{ success: true } | { success: false; error: string }>;getShortcuts: () => Promise<Record<string, unknown> | null>;saveShortcuts: (shortcuts: unknown) => Promise<{ success: boolean; error?: string }>;updateGlobalShortcut: (binding: {diff --git a/electron/ipc/handlers.ts b/electron/ipc/handlers.tsindex 7b9177c2c..8d242d9b5 100644--- a/electron/ipc/handlers.ts+++ b/electron/ipc/handlers.ts@@ -106,6 +106,7 @@ import {import { CompositorViewService } from "../native-bridge/services/compositorViewService";import { getMacPermissions, showPermissionsWindow } from "../permissions";import { scoreDeviceNameMatch } from "../recording/deviceNameMatching";+import { checkDiskSpace } from "../recording/diskSpaceCheck";import {describeSalvagedTake,nativeMacSalvageTarget,@@ -2283,6 +2284,18 @@ export function registerIpcHandlers(},);+ // Asked before every take starts. A disk that fills up mid-take used to be found only+ // when the take was saved, and the take was lost with it.+ ipcMain.handle("check-recording-storage", async () => {+ const status = await checkDiskSpace(RECORDINGS_DIR);+ if (!status.low) return { success: true };+ const availableMb = Math.max(0, Math.floor(status.availableBytes / (1024 * 1024)));+ return {+ success: false,+ error: mainT("dialogs", "recording.lowDiskSpace", { availableMb }),+ };+ });+ipcMain.handle("request-camera-access", async () => {if (process.platform !== "darwin") {return { success: true, granted: true, status: "granted" };diff --git a/electron/preload.ts b/electron/preload.tsindex feb3942df..9441718af 100644--- a/electron/preload.ts+++ b/electron/preload.ts@@ -490,6 +490,11 @@ contextBridge.exposeInMainWorld("electronAPI", {revealInFolder: (filePath: string) => {return ipcRenderer.invoke("reveal-in-folder", filePath);},+ checkRecordingStorage: () => {+ return ipcRenderer.invoke("check-recording-storage") as Promise<+ { success: true } | { success: false; error: string }+ >;+ },getShortcuts: () => {return ipcRenderer.invoke("get-shortcuts");},diff --git a/electron/recording/diskSpaceCheck.test.ts b/electron/recording/diskSpaceCheck.test.tsnew file mode 100644index 000000000..55970b60b--- /dev/null+++ b/electron/recording/diskSpaceCheck.test.ts@@ -0,0 +1,33 @@+import { mkdtemp, rm } from "node:fs/promises";+import { tmpdir } from "node:os";+import path from "node:path";+import { afterEach, beforeEach, describe, expect, it } from "vitest";+import { checkDiskSpace } from "./diskSpaceCheck";++describe("checkDiskSpace", () => {+ let dir: string;++ beforeEach(async () => {+ dir = await mkdtemp(path.join(tmpdir(), "openscreen-disk-space-"));+ });++ afterEach(async () => {+ await rm(dir, { recursive: true, force: true });+ });++ it("reports the real filesystem as not low, using a near-zero threshold", async () => {+ const status = await checkDiskSpace(dir, 1);+ expect(status.low).toBe(false);+ expect(status.availableBytes).toBeGreaterThan(0);+ });++ it("reports low when the threshold is set far above any real free space", async () => {+ const status = await checkDiskSpace(dir, Number.MAX_SAFE_INTEGER);+ expect(status.low).toBe(true);+ });++ it("does not throw and reports not-low for a directory that doesn't exist", async () => {+ const status = await checkDiskSpace(path.join(dir, "does-not-exist"));+ expect(status.low).toBe(false);+ });+});diff --git a/electron/recording/diskSpaceCheck.ts b/electron/recording/diskSpaceCheck.tsnew file mode 100644index 000000000..c94b07597--- /dev/null+++ b/electron/recording/diskSpaceCheck.ts@@ -0,0 +1,34 @@+// Pre-flight free-space check for recording start. Before this, the app had+// no disk-space awareness anywhere: a recording could run for its full+// duration and only fail once the user tried to save it, discarding the+// take. Catching it before capture starts costs one statfs() call and saves+// a wasted recording.+import fs from "node:fs/promises";++/** Recording output is usually well under this; below it, a take is likely to run out mid-capture. */+export const LOW_DISK_SPACE_THRESHOLD_BYTES = 500 * 1024 * 1024;++export interface DiskSpaceStatus {+ /** Bytes free on the filesystem backing the recordings directory. */+ availableBytes: number;+ low: boolean;+}++/**+ * Checks free space on the filesystem that backs `dir`. Never throws — a+ * platform or filesystem that doesn't support statfs (or a directory that+ * doesn't exist yet) reports as not-low, since a bad check must never block+ * a recording that would otherwise have worked.+ */+export async function checkDiskSpace(+ dir: string,+ thresholdBytes: number = LOW_DISK_SPACE_THRESHOLD_BYTES,+): Promise<DiskSpaceStatus> {+ try {+ const stats = await fs.statfs(dir);+ const availableBytes = stats.bavail * stats.bsize;+ return { availableBytes, low: availableBytes < thresholdBytes };+ } catch {+ return { availableBytes: Number.POSITIVE_INFINITY, low: false };+ }+}diff --git a/src/components/ai-edition/v4/AddAudioLayerDialog.tsx b/src/components/ai-edition/v4/AddAudioLayerDialog.tsxindex d10edf08d..c1112cb67 100644--- a/src/components/ai-edition/v4/AddAudioLayerDialog.tsx+++ b/src/components/ai-edition/v4/AddAudioLayerDialog.tsx@@ -160,6 +160,11 @@ export function AddAudioLayerDialog({return;}try {+ const storage = await window.electronAPI?.checkRecordingStorage?.();+ if (storage && !storage.success) {+ toast.error(storage.error);+ return;+ }const stream = await navigator.mediaDevices.getUserMedia({audio: { echoCancellation: true, noiseSuppression: true },});diff --git a/src/hooks/useScreenRecorder.nativeMacStartWarning.test.tsx b/src/hooks/useScreenRecorder.nativeMacStartWarning.test.tsxindex 16804bf82..3982706ef 100644--- a/src/hooks/useScreenRecorder.nativeMacStartWarning.test.tsx+++ b/src/hooks/useScreenRecorder.nativeMacStartWarning.test.tsx@@ -103,6 +103,22 @@ describe("useScreenRecorder native macOS start warnings", () => {expect(toast.error).toHaveBeenCalledWith("recording.microphoneDefaulted");});+ it("does not start a take the disk has no room for", async () => {+ api.checkRecordingStorage = vi.fn(async () => ({ success: false, error: "only 12 MB free" }));+ const view = renderHook(() => useScreenRecorder());+ await settle();++ await act(async () => {+ view.result.current.toggleRecording();+ });+ await settle(3_500);++ expect(api.checkRecordingStorage).toHaveBeenCalledOnce();+ expect(api.startNativeMacRecording).not.toHaveBeenCalled();+ expect(view.result.current.recording).toBe(false);+ expect(toast.error).toHaveBeenCalledWith("only 12 MB free");+ });+it("says so when the helper records without the microphone", async () => {api.startNativeMacRecording.mockResolvedValue({success: true,diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.tsindex c0114537e..cc77e907b 100644--- a/src/hooks/useScreenRecorder.ts+++ b/src/hooks/useScreenRecorder.ts@@ -1794,6 +1794,12 @@ export function useScreenRecorder(): UseScreenRecorderReturn {teardownMedia();return;}+ // Every path below records into the same folder, so one check covers them all. A+ // take that fills the disk is otherwise lost only when it is saved.+ const storage = await window.electronAPI.checkRecordingStorage?.();+ if (storage && !storage.success) {+ throw new Error(storage.error);+ }// Resolved once, for whichever path records the take (#995).const recordMicrophone = await shouldRecordMicrophone(microphoneEnabled);diff --git a/src/i18n/locales/ar/dialogs.json b/src/i18n/locales/ar/dialogs.jsonindex cf7c6f554..405545261 100644--- a/src/i18n/locales/ar/dialogs.json+++ b/src/i18n/locales/ar/dialogs.json@@ -88,5 +88,8 @@"audioFiles": "ملفات الصوت","openscreenProject": "مشروع OpenScreen","allFiles": "جميع الملفات"+ },+ "recording": {+ "lowDiskSpace": "لا توجد مساحة تخزين كافية لبدء التسجيل (لا يتوفر سوى {{availableMb}} ميجابايت). حرر بعض المساحة أو اختر مجلد تسجيلات آخر، ثم حاول مرة أخرى."}}diff --git a/src/i18n/locales/cs/dialogs.json b/src/i18n/locales/cs/dialogs.jsonindex 850e673c7..83c04edc8 100644--- a/src/i18n/locales/cs/dialogs.json+++ b/src/i18n/locales/cs/dialogs.json@@ -88,5 +88,8 @@"audioFiles": "Zvukové soubory","openscreenProject": "Projekt OpenScreen","allFiles": "Všechny soubory"+ },+ "recording": {+ "lowDiskSpace": "Nedostatek místa na disku pro zahájení nahrávání (volno pouze {{availableMb}} MB). Uvolněte místo nebo vyberte jinou složku pro nahrávky a zkuste to znovu."}}diff --git a/src/i18n/locales/de/dialogs.json b/src/i18n/locales/de/dialogs.jsonindex 2c5e70ccd..7081f5fde 100644--- a/src/i18n/locales/de/dialogs.json+++ b/src/i18n/locales/de/dialogs.json@@ -88,5 +88,8 @@"audioFiles": "Audiodateien","openscreenProject": "OpenScreen-Projekt","allFiles": "Alle Dateien"+ },+ "recording": {+ "lowDiskSpace": "Nicht genügend Speicherplatz, um die Aufnahme zu starten (nur {{availableMb}} MB frei). Gib Speicherplatz frei oder wähle einen anderen Ordner für Aufnahmen und versuche es erneut."}}diff --git a/src/i18n/locales/en/dialogs.json b/src/i18n/locales/en/dialogs.jsonindex 9cd0bbbbc..46eccd7f5 100644--- a/src/i18n/locales/en/dialogs.json+++ b/src/i18n/locales/en/dialogs.json@@ -88,5 +88,8 @@"audioFiles": "Audio files","openscreenProject": "OpenScreen project","allFiles": "All files"+ },+ "recording": {+ "lowDiskSpace": "Not enough disk space to start recording (only {{availableMb}} MB free). Free up space or choose a different recordings folder, then try again."}}diff --git a/src/i18n/locales/es/dialogs.json b/src/i18n/locales/es/dialogs.jsonindex 8f26a3aff..5c0f98430 100644--- a/src/i18n/locales/es/dialogs.json+++ b/src/i18n/locales/es/dialogs.json@@ -88,5 +88,8 @@"audioFiles": "Archivos de audio","openscreenProject": "Proyecto OpenScreen","allFiles": "Todos los archivos"+ },+ "recording": {+ "lowDiskSpace": "No hay suficiente espacio en disco para iniciar la grabación (solo quedan {{availableMb}} MB libres). Libera espacio o elige otra carpeta de grabaciones e inténtalo de nuevo."}}diff --git a/src/i18n/locales/fr/dialogs.json b/src/i18n/locales/fr/dialogs.jsonindex ad5b4edf6..94090d66a 100644--- a/src/i18n/locales/fr/dialogs.json+++ b/src/i18n/locales/fr/dialogs.json@@ -88,5 +88,8 @@"audioFiles": "Fichiers audio","openscreenProject": "Projet OpenScreen","allFiles": "Tous les fichiers"+ },+ "recording": {+ "lowDiskSpace": "Espace disque insuffisant pour démarrer l'enregistrement (seulement {{availableMb}} Mo disponibles). Libérez de l'espace ou choisissez un autre dossier d'enregistrements, puis réessayez."}}diff --git a/src/i18n/locales/it/dialogs.json b/src/i18n/locales/it/dialogs.jsonindex e8e326c91..2825c897a 100644--- a/src/i18n/locales/it/dialogs.json+++ b/src/i18n/locales/it/dialogs.json@@ -88,5 +88,8 @@"audioFiles": "File audio","openscreenProject": "Progetto OpenScreen","allFiles": "Tutti i file"+ },+ "recording": {+ "lowDiskSpace": "Spazio su disco insufficiente per avviare la registrazione (solo {{availableMb}} MB disponibili). Libera spazio o scegli un'altra cartella per le registrazioni, quindi riprova."}}diff --git a/src/i18n/locales/ja-JP/dialogs.json b/src/i18n/locales/ja-JP/dialogs.jsonindex c0c00ad80..0c97560c1 100644--- a/src/i18n/locales/ja-JP/dialogs.json+++ b/src/i18n/locales/ja-JP/dialogs.json@@ -88,5 +88,8 @@"audioFiles": "オーディオファイル","openscreenProject": "OpenScreen プロジェクト","allFiles": "すべてのファイル"+ },+ "recording": {+ "lowDiskSpace": "録画を開始するのに十分なディスク容量がありません(空き容量は{{availableMb}} MBのみ)。空き容量を確保するか、別の録画フォルダーを選択してから、もう一度お試しください。"}}diff --git a/src/i18n/locales/ko-KR/dialogs.json b/src/i18n/locales/ko-KR/dialogs.jsonindex 2b64240ae..747a082d9 100644--- a/src/i18n/locales/ko-KR/dialogs.json+++ b/src/i18n/locales/ko-KR/dialogs.json@@ -88,5 +88,8 @@"audioFiles": "오디오 파일","openscreenProject": "OpenScreen 프로젝트","allFiles": "모든 파일"+ },+ "recording": {+ "lowDiskSpace": "녹화를 시작할 디스크 공간이 부족합니다(사용 가능한 공간 {{availableMb}}MB). 공간을 확보하거나 다른 녹화 폴더를 선택한 후 다시 시도하세요."}}diff --git a/src/i18n/locales/pt-BR/dialogs.json b/src/i18n/locales/pt-BR/dialogs.jsonindex 88f163d99..6a9563e00 100644--- a/src/i18n/locales/pt-BR/dialogs.json+++ b/src/i18n/locales/pt-BR/dialogs.json@@ -88,5 +88,8 @@"audioFiles": "Arquivos de áudio","openscreenProject": "Projeto OpenScreen","allFiles": "Todos os Arquivos"+ },+ "recording": {+ "lowDiskSpace": "Espaço em disco insuficiente para iniciar a gravação (apenas {{availableMb}} MB livres). Libere espaço ou escolha outra pasta de gravações e tente novamente."}}diff --git a/src/i18n/locales/ru/dialogs.json b/src/i18n/locales/ru/dialogs.jsonindex 1f46a14fc..156049987 100644--- a/src/i18n/locales/ru/dialogs.json+++ b/src/i18n/locales/ru/dialogs.json@@ -88,5 +88,8 @@"audioFiles": "Аудиофайлы","openscreenProject": "Проект OpenScreen","allFiles": "Все файлы"+ },+ "recording": {+ "lowDiskSpace": "Недостаточно места на диске для начала записи (доступно только {{availableMb}} МБ). Освободите место или выберите другую папку для записей и повторите попытку."}}diff --git a/src/i18n/locales/tr/dialogs.json b/src/i18n/locales/tr/dialogs.jsonindex 6b01da744..9cc1f95ae 100644--- a/src/i18n/locales/tr/dialogs.json+++ b/src/i18n/locales/tr/dialogs.json@@ -88,5 +88,8 @@"audioFiles": "Ses dosyaları","openscreenProject": "OpenScreen Projesi","allFiles": "Tüm Dosyalar"+ },+ "recording": {+ "lowDiskSpace": "Kaydı başlatmak için yeterli disk alanı yok (yalnızca {{availableMb}} MB boş). Alan boşaltın veya farklı bir kayıt klasörü seçip tekrar deneyin."}}diff --git a/src/i18n/locales/vi/dialogs.json b/src/i18n/locales/vi/dialogs.jsonindex 452e80e2f..6bb2d313c 100644--- a/src/i18n/locales/vi/dialogs.json+++ b/src/i18n/locales/vi/dialogs.json@@ -88,5 +88,8 @@"audioFiles": "Tệp âm thanh","openscreenProject": "Dự án OpenScreen","allFiles": "Tất cả các tệp"+ },+ "recording": {+ "lowDiskSpace": "Không đủ dung lượng ổ đĩa để bắt đầu quay (chỉ còn {{availableMb}} MB trống). Hãy giải phóng dung lượng hoặc chọn thư mục bản ghi khác rồi thử lại."}}diff --git a/src/i18n/locales/zh-CN/dialogs.json b/src/i18n/locales/zh-CN/dialogs.jsonindex db4f12730..2d6b3caac 100644--- a/src/i18n/locales/zh-CN/dialogs.json+++ b/src/i18n/locales/zh-CN/dialogs.json@@ -88,5 +88,8 @@"audioFiles": "音频文件","openscreenProject": "OpenScreen 项目","allFiles": "所有文件"+ },+ "recording": {+ "lowDiskSpace": "磁盘空间不足,无法开始录制(仅剩 {{availableMb}} MB 可用空间)。请释放空间或选择其他录制文件夹,然后重试。"}}diff --git a/src/i18n/locales/zh-TW/dialogs.json b/src/i18n/locales/zh-TW/dialogs.jsonindex f4830a611..dee723462 100644--- a/src/i18n/locales/zh-TW/dialogs.json+++ b/src/i18n/locales/zh-TW/dialogs.json@@ -88,5 +88,8 @@"audioFiles": "音訊檔案","openscreenProject": "OpenScreen 專案","allFiles": "所有檔案"+ },+ "recording": {+ "lowDiskSpace": "磁碟空間不足,無法開始錄製(僅剩 {{availableMb}} MB 可用空間)。請釋放空間或選擇其他錄製資料夾,然後再試一次。"}}