From 5e32d32913f53cc265941f6b1c11d048cb1e6f6a Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Wed, 25 Sep 2024 12:12:14 -0500 Subject: [PATCH] fix: close all open sheets before closing window on macOS (#43954) Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: John Beutner --- shell/browser/native_window_mac.mm | 5 ++++- spec/api-browser-window-spec.ts | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index f91adfbd7acc..add17177eb2a 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -347,8 +347,11 @@ void NativeWindowMac::Close() { // [window_ performClose:nil], the window won't close properly // even after the user has ended the sheet. // Ensure it's closed before calling [window_ performClose:nil]. - if ([window_ attachedSheet]) + // If multiple sheets are open, they must all be closed. + while ([window_ attachedSheet]) { [window_ endSheet:[window_ attachedSheet]]; + } + DCHECK_EQ([[window_ sheets] count], 0UL); // window_ could be nil after performClose. bool should_notify = is_modal() && parent() && IsVisible(); diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index d5d21b962975..57a50521b384 100644 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -116,6 +116,14 @@ describe('BrowserWindow module', () => { await closed; }); + it('should work if called when multiple messageBoxes are showing', async () => { + const closed = once(w, 'closed'); + dialog.showMessageBox(w, { message: 'Hello Error' }); + dialog.showMessageBox(w, { message: 'Hello Error' }); + w.close(); + await closed; + }); + it('closes window without rounded corners', async () => { await closeWindow(w); w = new BrowserWindow({ show: false, frame: false, roundedCorners: false });