From 36076aaf2a3efd77213d11474c38d81177e1e7be Mon Sep 17 00:00:00 2001 From: makaradam Date: Sat, 2 May 2026 13:08:52 +0200 Subject: [PATCH] fix: address code review feedback on custom close dialog --- electron/main.ts | 7 ++- .../video-editor/UnsavedChangesDialog.tsx | 63 +++++++++---------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/electron/main.ts b/electron/main.ts index 5540419..94f0a42 100644 --- a/electron/main.ts +++ b/electron/main.ts @@ -252,6 +252,7 @@ function updateTrayMenu(recording: boolean = false) { let editorHasUnsavedChanges = false; let isForceClosing = false; +let isCloseConfirmInFlight = false; ipcMain.on("set-has-unsaved-changes", (_, hasChanges: boolean) => { editorHasUnsavedChanges = hasChanges; @@ -283,9 +284,10 @@ function createEditorWindowWrapper() { editorHasUnsavedChanges = false; mainWindow.on("close", (event) => { - if (isForceClosing || !editorHasUnsavedChanges) return; + if (isForceClosing || !editorHasUnsavedChanges || isCloseConfirmInFlight) return; event.preventDefault(); + isCloseConfirmInFlight = true; const windowToClose = mainWindow; if (!windowToClose || windowToClose.isDestroyed()) return; @@ -294,6 +296,7 @@ function createEditorWindowWrapper() { windowToClose.webContents.send("request-close-confirm"); ipcMain.once("close-confirm-response", (_, choice: "save" | "discard" | "cancel") => { + isCloseConfirmInFlight = false; if (!windowToClose || windowToClose.isDestroyed()) return; if (choice === "save") { @@ -306,7 +309,7 @@ function createEditorWindowWrapper() { } else if (choice === "discard") { forceCloseEditorWindow(windowToClose); } - // "cancel": do nothing, window stays open + // "cancel": flag reset, window stays open }); }); } diff --git a/src/components/video-editor/UnsavedChangesDialog.tsx b/src/components/video-editor/UnsavedChangesDialog.tsx index 9b8ee03..a0623ba 100644 --- a/src/components/video-editor/UnsavedChangesDialog.tsx +++ b/src/components/video-editor/UnsavedChangesDialog.tsx @@ -1,4 +1,11 @@ -import { Save, Trash2, X } from "lucide-react"; +import { Save, Trash2 } from "lucide-react"; +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; import { useScopedT } from "@/contexts/I18nContext"; interface UnsavedChangesDialogProps { @@ -17,41 +24,33 @@ export function UnsavedChangesDialog({ const td = useScopedT("dialogs"); const tc = useScopedT("common"); - if (!isOpen) return null; - return ( - <> -
-
-
- OpenScreen -

- {td("unsavedChanges.title")} -

- -
+ !open && onCancel()}> + + +
+ + + {td("unsavedChanges.title")} + +
+

{td("unsavedChanges.message")}

-

{td("unsavedChanges.detail")}

+ + {td("unsavedChanges.detail")} +
-
- + + ); }