Skip to content

Commit c65f41d

Browse files
fix: don't assign NSAlert to window which is not visible (electron#22672)
* fix: don't assign NSAlert to window which is not visible Without this change it's possible to create message box which can't be dismissed on mac. * fixup! fix: don't assign NSAlert to window which is not visible * fixup! fix: don't assign NSAlert to window which is not visible
1 parent 1746ae8 commit c65f41d

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

docs/api/dialog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ Shows a message box, it will block the process until the message box is closed.
269269
It returns the index of the clicked button.
270270

271271
The `browserWindow` argument allows the dialog to attach itself to a parent window, making it modal.
272+
If `browserWindow` is not shown dialog will not be attached to it. In such case It will be displayed as independed window.
272273

273274
### `dialog.showMessageBox([browserWindow, ]options)`
274275

shell/browser/ui/message_box_mac.mm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ int ShowMessageBoxSync(const MessageBoxSettings& settings) {
9797
NSAlert* alert = CreateNSAlert(settings);
9898

9999
// Use runModal for synchronous alert without parent, since we don't have a
100-
// window to wait for.
101-
if (!settings.parent_window)
100+
// window to wait for. Also use it when window is provided but it is not
101+
// shown as it would be impossible to dismiss the alert if it is connected
102+
// to invisible window (see #22671).
103+
if (!settings.parent_window || !settings.parent_window->IsVisible())
102104
return [[alert autorelease] runModal];
103105

104106
__block int ret_code = -1;

0 commit comments

Comments
 (0)