Skip to content

Commit

Permalink
fix: don't assign NSAlert to window which is not visible (#23089)
Browse files Browse the repository at this point in the history
* 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

* Update docs/api/dialog.md

Co-authored-by: Cezary Kulakowski <cezary@openfin.co>
Co-authored-by: John Kleinschmidt <jkleinsc@github.com>
  • Loading branch information
3 people committed Apr 14, 2020
1 parent 372c5b9 commit 97010bf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/api/dialog.md
Expand Up @@ -254,6 +254,7 @@ Shows a message box, it will block the process until the message box is closed.
It returns the index of the clicked button.

The `browserWindow` argument allows the dialog to attach itself to a parent window, making it modal.
If the `browserWindow` is not shown, the dialog will not be attached to it. In that case it will be displayed as an independent window.

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

Expand Down
6 changes: 4 additions & 2 deletions shell/browser/ui/message_box_mac.mm
Expand Up @@ -97,8 +97,10 @@ int ShowMessageBoxSync(const MessageBoxSettings& settings) {
NSAlert* alert = CreateNSAlert(settings);

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

__block int ret_code = -1;
Expand Down

0 comments on commit 97010bf

Please sign in to comment.