Fix exception that happens on focus change

Summary:
Fixing the previous resulted in a next exception, where blur / focus might be triggered directly as side effect of some running logic. I think this happens when entering a debugger statement causing the window to loose focus in favor of the devtools.

Wrapped the logic in setImmediate to make sure that it runs on its own stack, since this will prevent any potential future issues with programmatically focussing / blurring as well.

Reviewed By: jknoxville

Differential Revision: D26814270

fbshipit-source-id: 5ca430653a219d3c98d8bf925277de67d8a9eb20
This commit is contained in:
Michel Weststrate
2021-03-04 05:59:40 -08:00
committed by Facebook GitHub Bot
parent 67e87c2fa5
commit 163799cf89

View File

@@ -38,15 +38,19 @@ export const uriComponents = (url: string): Array<string> => {
export default (store: Store, _logger: Logger) => {
const currentWindow = remote.getCurrentWindow();
currentWindow.on('focus', () => {
store.dispatch({
type: 'windowIsFocused',
payload: {isFocused: true, time: Date.now()},
setImmediate(() => {
store.dispatch({
type: 'windowIsFocused',
payload: {isFocused: true, time: Date.now()},
});
});
});
currentWindow.on('blur', () => {
store.dispatch({
type: 'windowIsFocused',
payload: {isFocused: false, time: Date.now()},
setImmediate(() => {
store.dispatch({
type: 'windowIsFocused',
payload: {isFocused: false, time: Date.now()},
});
});
});