fluid-lab / gamepad-navigator

GSoC 2020 project
Other
6 stars 10 forks source link

Destroying input manager on "blur" has unwanted side effects. #110

Closed duhrer closed 7 months ago

duhrer commented 8 months ago

Currently, we have an "input mapper manager" that checks window visibility and:

  1. Creates an inputMapper when a window becomes visible.
  2. Destroys the inputMapper when the window is no longer visible.

This results in constantly creating/destroying components when switching windows. Focusing on the dev tools makes the window appear to be invisible. Since we use the new rendering infrastructure, all of our markup is cleared when the component is removed. This makes it very difficult to inspect elements in our markup using the dev tools.

My gut feel is that we should collapse the input mapper manager into the input mapper and have it deactivate/reactivate itself in response to visibility changes. However, this would require careful testing to avoid unresponsive windows.

If we can figure a way to more tightly detect which window dev tools are open in, perhaps the fix can be limited to that and we can leave the input mapper manager alone.

duhrer commented 8 months ago

In reading threads like this one, it seems like we can detect whether the console is open using code like:

var isOpen = false;
var consoleCheck = function () { isOpen = true; }
console.log("%c", consoleCheck);

if (isOpen) {
    // Do something.
}
else {
    // Do something else.
}
duhrer commented 8 months ago

Another thought I've had regarding this is to use the worker to track which window is open. As long as no new window receives focus via a listener for onpageshow or onfocus, treat the last window as the one that's open.

duhrer commented 8 months ago

We might also check to see if the current window matches chrome.windows.getLastFocused before responding to any inputs. Then the onblur/onpagehide code would just need to close any open modals.

duhrer commented 8 months ago

This may have to be addressed sooner rather than later, as the new onscreen keyboard I'm working on for #84 doesn't work at all unless I disable the call to destroy on blur.

duhrer commented 7 months ago

This work has been merged and will be included in the upcoming 1.0 release.