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(macos): say when a restart discarded the take and drop the empty file a failed start leaves

entity-0-0-252eda0e6820d
diff --git a/electron/ipc/handlers.ts b/electron/ipc/handlers.ts
index 132a879cb..ae00fd98b 100644
--- a/electron/ipc/handlers.ts
+++ b/electron/ipc/handlers.ts
@@ -3216,6 +3216,7 @@ export function registerIpcHandlers(
};
} catch (error) {
console.error("Failed to start native macOS recording:", error);
+ const failedOutputPath = nativeMacCaptureTargetPath;
nativeMacCaptureProcess?.kill();
nativeMacCaptureProcess = null;
nativeMacCaptureTargetPath = null;
@@ -3226,6 +3227,16 @@ export function registerIpcHandlers(
nativeMacPauseStartedAtMs = null;
nativeMacPauseRanges = [];
nativeMacIsPaused = false;
+ if (failedOutputPath) {
+ await fs
+ .stat(failedOutputPath)
+ .then((statInfo) =>
+ statInfo.isFile() && statInfo.size === 0
+ ? fs.rm(failedOutputPath, { force: true })
+ : undefined,
+ )
+ .catch(() => undefined);
+ }
await stopCursorRecording();
return { success: false, error: error instanceof Error ? error.message : String(error) };
}
diff --git a/src/hooks/useScreenRecorder.nativeMacStartWarning.test.tsx b/src/hooks/useScreenRecorder.nativeMacStartWarning.test.tsx
index a56c7bcc4..30df54055 100644
--- a/src/hooks/useScreenRecorder.nativeMacStartWarning.test.tsx
+++ b/src/hooks/useScreenRecorder.nativeMacStartWarning.test.tsx
@@ -173,6 +173,31 @@ describe("useScreenRecorder native macOS start warnings", () => {
}
});
+ it("says the previous take was discarded when the take after a Restart never starts", async () => {
+ const view = renderHook(() => useScreenRecorder());
+ await settle();
+
+ await act(async () => {
+ view.result.current.toggleRecording();
+ });
+ await settle(3_500);
+ expect(view.result.current.recording).toBe(true);
+
+ api.startNativeMacRecording.mockResolvedValue({
+ success: false,
+ error: "Timed out waiting for native macOS capture to start",
+ });
+
+ await act(async () => {
+ await view.result.current.restartRecording();
+ });
+ await settle();
+
+ expect(api.stopNativeMacRecording).toHaveBeenCalledWith(true);
+ expect(api.startNativeMacRecording).toHaveBeenCalledTimes(2);
+ expect(toast.error).toHaveBeenCalledWith("Restart failed. The previous take was discarded.");
+ });
+
// macOS 13 and 14 have no `captureMicrophone`: a saved "mic on" would ask for the
// microphone and record a take without it (#700).
it("does not apply a saved microphone on macOS 14", async () => {
diff --git a/src/hooks/useScreenRecorder.ts b/src/hooks/useScreenRecorder.ts
index 33a6039aa..c20d31c13 100644
--- a/src/hooks/useScreenRecorder.ts
+++ b/src/hooks/useScreenRecorder.ts
@@ -2305,6 +2305,9 @@ export function useScreenRecorder(): UseScreenRecorderReturn {
try {
await finalizeNativeMacRecording(true);
await startRecording();
+ if (!nativeMacRecording.current) {
+ toast.error("Restart failed. The previous take was discarded.");
+ }
} finally {
restarting.current = false;
}