Skip to content

Create polished demo videos without editing skills. Mac/Windows/Linux

fix: retain import rollback until the editor accepts its result

webadderallcc023ad3bac2
diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.ts
index d7a1a9eb..f4a030d4 100644
--- a/electron/electron-env.d.ts
+++ b/electron/electron-env.d.ts
@@ -755,7 +755,10 @@ interface Window {
getRecordingThumbnail: (
filePath: string,
) => Promise<import("../src/types/recordingLibrary").LibraryResult<string>>;
- finishRecordingImport: (keepPath: string) => Promise<{ success: boolean; error?: string }>;
+ finishRecordingImport: (
+ keepPath: string,
+ commit?: boolean,
+ ) => Promise<{ success: boolean; error?: string }>;
cancelRecordingImport: () => Promise<{ success: boolean }>;
listRecordings: () => Promise<
import("../src/types/recordingLibrary").LibraryResult<
diff --git a/electron/ipc/register/project.ts b/electron/ipc/register/project.ts
index 5430e154..885e5ddb 100644
--- a/electron/ipc/register/project.ts
+++ b/electron/ipc/register/project.ts
@@ -229,18 +229,19 @@ export function registerProjectHandlers() {
},
);
};
- ipcMain.handle("finish-recording-import", async (event, keepPath: string) => {
+ ipcMain.handle("finish-recording-import", async (event, keepPath: string, commit = false) => {
if (imports.has(event.sender.id))
return { success: false, error: "Import is still running" };
const outputs = pendingImports.get(event.sender.id);
- // Transfer the final source before async cleanup can race renderer teardown.
- outputs?.delete(keepPath);
+ // Commit only after the renderer confirms that its project is still active.
+ if (commit) outputs?.delete(keepPath);
try {
for (const output of outputs ?? []) {
+ if (output === keepPath) continue;
await discardRecordingImport(output);
outputs?.delete(output);
}
- pendingImports.delete(event.sender.id);
+ if (!outputs?.size) pendingImports.delete(event.sender.id);
return { success: true };
} catch (error) {
return { success: false, error: String(error) };
diff --git a/electron/preload.ts b/electron/preload.ts
index ee15d748..02273b23 100644
--- a/electron/preload.ts
+++ b/electron/preload.ts
@@ -789,8 +789,8 @@ contextBridge.exposeInMainWorld("electronAPI", {
},
getRecordingThumbnail: (filePath: string) =>
ipcRenderer.invoke("get-recording-thumbnail", filePath),
- finishRecordingImport: (keepPath: string) =>
- ipcRenderer.invoke("finish-recording-import", keepPath),
+ finishRecordingImport: (keepPath: string, commit?: boolean) =>
+ ipcRenderer.invoke("finish-recording-import", keepPath, commit),
cancelRecordingImport: () => ipcRenderer.invoke("cancel-recording-import"),
listRecordings: () => ipcRenderer.invoke("list-recordings"),
setRecordingsRemoved: (paths: string[], removed: boolean) =>
diff --git a/src/components/video-editor/library/useRecordingLibrary.ts b/src/components/video-editor/library/useRecordingLibrary.ts
index 78d9bccd..69ef00fd 100644
--- a/src/components/video-editor/library/useRecordingLibrary.ts
+++ b/src/components/video-editor/library/useRecordingLibrary.ts
@@ -184,12 +184,16 @@ export function useRecordingLibrary(
const { project, timeline, ui, appearance } = current.current;
if (project.videoSourcePath !== source)
throw new Error("The project changed while importing. Add the recordings again.");
- // Commit ownership before exposing the source to project saves or renderer teardown.
- const committed = await window.electronAPI.finishRecordingImport(media.path);
- if (!committed.success)
- throw new Error(committed.error || "Could not finalize imported media");
+ // Prepare cleanup while retaining rollback ownership until the project check passes.
+ const prepared = await window.electronAPI.finishRecordingImport(media.path);
+ if (!prepared.success)
+ throw new Error(prepared.error || "Could not finalize imported media");
if (current.current.project.videoSourcePath !== source)
throw new Error("The project changed while importing. Add the recordings again.");
+ // Send acceptance before synchronous project state updates; no await can switch projects here.
+ void window.electronAPI
+ .finishRecordingImport(media.path, true)
+ .catch((error) => console.warn("Could not accept imported media", error));
ui.clipInitializedRef.current = true;
ui.autoFullTrackClipIdRef.current = null;
ui.autoFullTrackClipEndMsRef.current = null;
@@ -223,7 +227,10 @@ export function useRecordingLibrary(
if (!cancelled.current) toast.error(`Could not add video: ${String(error)}`);
} finally {
try {
- const cleanup = await window.electronAPI.finishRecordingImport(retainedSource!);
+ const cleanup = await window.electronAPI.finishRecordingImport(
+ retainedSource!,
+ true,
+ );
if (!cleanup.success)
console.warn("Could not clean up temporary imports", cleanup.error);
} catch (error) {