Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: BrowserWindow.maximize Does Not Show Window on macOS #32947

Closed
3 tasks done
dsanders11 opened this issue Feb 17, 2022 · 5 comments · Fixed by #32949
Closed
3 tasks done

[Bug]: BrowserWindow.maximize Does Not Show Window on macOS #32947

dsanders11 opened this issue Feb 17, 2022 · 5 comments · Fixed by #32949
Assignees
Labels
14-x-y 15-x-y 16-x-y 17-x-y 18-x-y bug 🪲 has-repro-gist Issue can be reproduced with code at https://gist.github.com/ platform/macOS

Comments

@dsanders11
Copy link
Member

Preflight Checklist

Electron Version

19.0.0-nightly.20220209

What operating system are you using?

macOS

Operating System Version

macOS 11.6.2

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

Maximizing a window which isn't being shown should show the window. According to the docs for BrowserWindow.maximize():

Maximizes the window. This will also show (but not focus) the window if it isn't being displayed already.

Actual Behavior

On macOS, the window is not shown, but window.isMaximized() returns true, and a subsequent window.show() will show a maximized window as expected.

Testcase Gist URL

https://gist.github.com/09e5ef031f69be2cce1e23c5174d6e5b

Additional Information

Tested on Windows 10 and Ubuntu and it works as expected, so this looks to be just macOS.

@Sankingraitus
Copy link

@Global-internet

@bpasero
Copy link
Contributor

bpasero commented May 27, 2022

@dsanders11 I think this fix is not complete. From the docs:

Maximizes the window. This will also show (but not focus) the window if it isn't being displayed already

With your change, the window will still not be visible but rather put behind the "key" (active) window. I would expect that the window is put above the active window and thus becomes visible.

@dsanders11
Copy link
Member Author

With your change, the window will still not be visible but rather put behind the "key" (active) window. I would expect that the window is put above the active window and thus becomes visible.

The associated PR here simply calls through to window.showInactive(), so any incorrect behavior as described would be as a result of that method.

That said, I can't reproduce this. In my testing it puts the second, unfocused window in front in z-order. Here's the fiddle I'm using to test, on macOS 12.4 and Electron v20.0.0-alpha.1. The second (unshown) window is maximized after 8 seconds. In my tests, it always put above the active window, but does not take focus (as expected).

If you have a reproduce case, happy to take a look. But I'd suspect any buggy behavior will be in window.showInactive().

@bpasero
Copy link
Contributor

bpasero commented May 28, 2022

@dsanders11 yeah, I am also trying out in a Fiddle and I do not see the behaviour of VSCode, but I suspect this is due to how the issue reproduces in VS Code: users have reported that this issue reproduces when they launch VS Code from a terminal while VS Code is already running, so this also involves VS Code being inactive as application and another instance of VS Code trying to bring the first instance to front. To clarify:

  • one instance of VS Code is running with a window active and focused
  • user switches to OS terminal, VS Code is no longer active and focused
  • user types code folder path to open a new window on the folder
  • this launches a separate VS Code process for a very short moment that talks to the existing running instance
  • then it terminates after having send a payload to the first instance
  • the first instance opens a second window
  • this second window is initially show: false and then window.maximize
  • previously this would not show the window as inactive, but with your change it does
  • we check on window.isVisible to decide if we need to call window.show or not
  • now window.isVisible returns true even though the second window is behind the first window

To clarify: in VS Code we have a condition that sets show: false when the window to open is either maximized or fullscreen. We do that because otherwise there is an ugly transition from normal window bounds to maximized or fullscreen that we want to prevent. As such, in those cases we simply call window.maximize first and then window.show. To be honest, I would love to drop this hack and just have a way to pass maximized: true or fullscreen: true right when creating the window so that we can remove this code on our end, I will file an issue on that maybe.

@bpasero
Copy link
Contributor

bpasero commented May 28, 2022

Opened: #34368

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
14-x-y 15-x-y 16-x-y 17-x-y 18-x-y bug 🪲 has-repro-gist Issue can be reproduced with code at https://gist.github.com/ platform/macOS
Projects
No open projects
Status: Fixed for Next Release
Development

Successfully merging a pull request may close this issue.

4 participants