mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Handle gamepads more gracefully based in window focus
This commit is contained in:
parent
440675fbee
commit
9c84b8268f
1 changed files with 4 additions and 2 deletions
|
@ -373,14 +373,14 @@ require(['apphost'], function (appHost) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function attachGamepad(e) {
|
function attachGamepad(e) {
|
||||||
if (isGamepadConnected()) {
|
if (isGamepadConnected() && document.hasFocus()) {
|
||||||
console.log("Gamepad connected! Starting input loop");
|
console.log("Gamepad connected! Starting input loop");
|
||||||
startInputLoop();
|
startInputLoop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function dettachGamepad(e) {
|
function dettachGamepad(e) {
|
||||||
if (!isGamepadConnected()) {
|
if (!isGamepadConnected() || !document.hasFocus()) {
|
||||||
console.log("Gamepad disconnected! No other gamepads are connected, stopping input loop");
|
console.log("Gamepad disconnected! No other gamepads are connected, stopping input loop");
|
||||||
stopInputLoop();
|
stopInputLoop();
|
||||||
} else {
|
} else {
|
||||||
|
@ -391,6 +391,8 @@ require(['apphost'], function (appHost) {
|
||||||
// Event Listeners for any change in gamepads' state.
|
// Event Listeners for any change in gamepads' state.
|
||||||
window.addEventListener("gamepaddisconnected", dettachGamepad);
|
window.addEventListener("gamepaddisconnected", dettachGamepad);
|
||||||
window.addEventListener("gamepadconnected", attachGamepad);
|
window.addEventListener("gamepadconnected", attachGamepad);
|
||||||
|
window.addEventListener("blur", dettachGamepad);
|
||||||
|
window.addEventListener("focus", attachGamepad);
|
||||||
|
|
||||||
// The gamepadInputEmulation is a string property that exists in JavaScript UWAs and in WebViews in UWAs.
|
// The gamepadInputEmulation is a string property that exists in JavaScript UWAs and in WebViews in UWAs.
|
||||||
// It won't exist in Win8.1 style apps or browsers.
|
// It won't exist in Win8.1 style apps or browsers.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue