mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-17 19:08:18 -07:00
Load gamepadtokey.js only when is necessary
This commit is contained in:
parent
af75183d2a
commit
c60dbbb3ae
@ -254,11 +254,7 @@ require(['apphost'], function (appHost) {
|
|||||||
function runInputLoop() {
|
function runInputLoop() {
|
||||||
// Get the latest gamepad state.
|
// Get the latest gamepad state.
|
||||||
var gamepads;
|
var gamepads;
|
||||||
if (navigator.getGamepads) {
|
|
||||||
gamepads = navigator.getGamepads();
|
gamepads = navigator.getGamepads();
|
||||||
} else if (navigator.webkitGetGamepads) {
|
|
||||||
gamepads = navigator.webkitGetGamepads();
|
|
||||||
}
|
|
||||||
gamepads = gamepads || [];
|
gamepads = gamepads || [];
|
||||||
var i;
|
var i;
|
||||||
var j;
|
var j;
|
||||||
|
@ -197,30 +197,30 @@ define(['connectionManager', 'playbackManager', 'events', 'inputManager', 'focus
|
|||||||
events.on(apiClient, "message", onMessageReceived);
|
events.on(apiClient, "message", onMessageReceived);
|
||||||
}
|
}
|
||||||
|
|
||||||
function enableNativeGamepadKeyMapping() {
|
function attachgamepad(e) {
|
||||||
if (window.navigator && "string" == typeof window.navigator.gamepadInputEmulation) {
|
if (navigator.getGamepads.length > 0) {
|
||||||
window.navigator.gamepadInputEmulation = "keyboard";
|
require(["components/serverNotifications/gamepadtokey"]);
|
||||||
return true;
|
console.log("Gamepad connected! Attaching gamepadtokey.js script");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
function dettachgamepad(e) {
|
||||||
}
|
delete require.cache[require(["components/serverNotifications/gamepadtokey"])];
|
||||||
|
console.log("Gamepad disconnected! Dettaching gamepadtokey.js");
|
||||||
function isGamepadSupported() {
|
|
||||||
return "ongamepadconnected" in window || navigator.getGamepads || navigator.webkitGetGamepads;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connectionManager.getApiClients().forEach(bindEvents);
|
connectionManager.getApiClients().forEach(bindEvents);
|
||||||
|
|
||||||
events.on(connectionManager, 'apiclientcreated', function (e, newApiClient) {
|
events.on(connectionManager, 'apiclientcreated', function (e, newApiClient) {
|
||||||
bindEvents(newApiClient);
|
bindEvents(newApiClient);
|
||||||
});
|
});
|
||||||
|
if (navigator.getGamepads()[0] != null) {
|
||||||
if (!enableNativeGamepadKeyMapping() && isGamepadSupported()) {
|
|
||||||
require(["components/serverNotifications/gamepadtokey"]);
|
require(["components/serverNotifications/gamepadtokey"]);
|
||||||
|
console.log("Gamepad connected! Attaching gamepadtokey.js script");
|
||||||
|
window.addEventListener("gamepaddisconnected", dettachgamepad);
|
||||||
|
} else {
|
||||||
|
window.addEventListener("gamepadconnected", attachgamepad);
|
||||||
|
console.log("No gamepad connected to this device");
|
||||||
}
|
}
|
||||||
|
// require(["components/serverNotifications/mouseManager"]);
|
||||||
require(["components/serverNotifications/mouseManager"]);
|
|
||||||
|
|
||||||
return serverNotifications;
|
return serverNotifications;
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user