Browse Source

fix: don't assign NSAlert to window which is not visible (#23088)

* 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

Co-authored-by: Cezary Kulakowski <[email protected]>
trop[bot] 5 years ago
parent
commit
331125d35a
2 changed files with 5 additions and 2 deletions
  1. 1 0
      docs/api/dialog.md
  2. 4 2
      shell/browser/ui/message_box_mac.mm

+ 1 - 0
docs/api/dialog.md

@@ -269,6 +269,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 `browserWindow` is not shown dialog will not be attached to it. In such case It will be displayed as independed window.
 
 ### `dialog.showMessageBox([browserWindow, ]options)`
 

+ 4 - 2
shell/browser/ui/message_box_mac.mm

@@ -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;