Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
fix: notify focus change right away rather not on next tick #14453
Description of Change
This issue fixes #13913. There was a problem with two windows fighting for focus because the focus notification was being sent on next tick.
Notes: Fixed windows multiple windows focus bug.
focus event is meant to be emitted after the window is focused. So behaviors on all platforms are matched, and issues like #3893 can be avoided.
OnWidgetActivationChanged method is called when the window is in the middle of changing focus, so emitting
focus here breaks the behavior, and can crash Electron if user decides to close the window now.
My solution was to delay the event one tick later, which fixed part of the problem but it was not the right solution.
We probably have to find out when the views library has just finished the focus changing, and emitting the event there.
OK so did a bunch of work on this today, there are other events we can use to get focus but they introduce other race conditions with the window creation and the first observer being added. The easiest solution to get this fixed in 3.0 is to reintroduce the next tick delay but later in the call stack so it only affects the JS emit calls
https://gist.github.com/7eb20129c41f6fc95999404d507fe438 reproduces the DCHECK failure above
Looks like Mac CI is failing with same DCHECK error: