Code review tweaks
This commit is contained in:
@@ -15,6 +15,7 @@ import globalize from 'lib/globalize';
|
||||
import browser from 'scripts/browser';
|
||||
import Dashboard from 'utils/dashboard';
|
||||
import shell from 'scripts/shell';
|
||||
import keyboardNavigation from 'scripts/keyboardNavigation';
|
||||
|
||||
const UserSettingsPage: FC = () => {
|
||||
const { user: currentUser } = useApi();
|
||||
@@ -47,7 +48,7 @@ const UserSettingsPage: FC = () => {
|
||||
}
|
||||
|
||||
// gamepad toggle unavailable on EdgeUWP, and smoothscroll unavailable on non-TV layout
|
||||
const isControlsPageEmpty = browser.edgeUwp && !layoutManager.tv;
|
||||
const isControlsPageEmpty = !keyboardNavigation.canEnableGamepad() && !layoutManager.tv;
|
||||
|
||||
return (
|
||||
<Page
|
||||
|
||||
@@ -3,7 +3,7 @@ import toast from '../../../components/toast/toast';
|
||||
import globalize from '../../../lib/globalize';
|
||||
import appSettings from '../../../scripts/settings/appSettings';
|
||||
import Events from '../../../utils/events.ts';
|
||||
import browser from 'scripts/browser';
|
||||
import keyboardNavigation from 'scripts/keyboardNavigation';
|
||||
|
||||
export default function (view) {
|
||||
function submit(e) {
|
||||
@@ -20,8 +20,9 @@ export default function (view) {
|
||||
}
|
||||
|
||||
view.addEventListener('viewshow', function () {
|
||||
view.querySelector('.enableGamepadContainer').classList.toggle('hide', !keyboardNavigation.canEnableGamepad());
|
||||
view.querySelector('.smoothScrollContainer').classList.toggle('hide', !layoutManager.tv);
|
||||
view.querySelector('.enableGamepadContainer').classList.toggle('hide', browser.edgeUwp);
|
||||
|
||||
view.querySelector('.chkEnableGamepad').checked = appSettings.enableGamepad();
|
||||
view.querySelector('.chkSmoothScroll').checked = appSettings.enableSmoothScroll();
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ const KeyAliases = {
|
||||
* Keys used for keyboard navigation.
|
||||
*/
|
||||
const NavigationKeys = ['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'BrowserHome', 'Find'];
|
||||
|
||||
/**
|
||||
* Keys used for media playback control.
|
||||
*/
|
||||
@@ -275,6 +276,11 @@ export function enable() {
|
||||
});
|
||||
}
|
||||
|
||||
export function canEnableGamepad() {
|
||||
// Not needed for UWP
|
||||
return !browser.edgeUwp;
|
||||
}
|
||||
|
||||
// Gamepad initialisation. No script is required if no gamepads are present at init time, saving a bit of resources.
|
||||
// Whenever the gamepad is connected, we hand all the control of the gamepad to gamepadtokey.js by removing the event handler
|
||||
function attachGamepadScript() {
|
||||
@@ -284,13 +290,13 @@ function attachGamepadScript() {
|
||||
}
|
||||
|
||||
// No need to check for gamepads manually at load time, the eventhandler will be fired for that
|
||||
// Not needed for UWP
|
||||
if (navigator.getGamepads && appSettings.enableGamepad() && !browser.edgeUwp) {
|
||||
if (navigator.getGamepads && appSettings.enableGamepad() && canEnableGamepad()) {
|
||||
window.addEventListener('gamepadconnected', attachGamepadScript);
|
||||
}
|
||||
|
||||
export default {
|
||||
enable: enable,
|
||||
getKeyName: getKeyName,
|
||||
isNavigationKey: isNavigationKey
|
||||
isNavigationKey: isNavigationKey,
|
||||
canEnableGamepad: canEnableGamepad
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user