Add gamepad enabling/disabling

This commit is contained in:
Dmitry Lyzo 2021-03-28 17:11:00 +03:00
parent c7b05ba130
commit 7974fbcbaa
8 changed files with 90 additions and 2 deletions

View File

@ -0,0 +1,24 @@
<div id="controlsPreferencesPage" data-role="page" class="page libraryPage userPreferencesPage noSecondaryNavPage" data-title="${Controls}" data-menubutton="true">
<div class="padded-left padded-right padded-bottom-page">
<form style="margin: 0 auto;">
<div class="verticalSection verticalSection-extrabottompadding">
<h2 class="sectionTitle">
${Controls}
</h2>
<div class="checkboxContainer checkboxContainer-withDescription">
<label>
<input type="checkbox" is="emby-checkbox" class="chkEnableGamepad" />
<span>${LabelEnableGamepad}</span>
</label>
<div class="fieldDescription checkboxFieldDescription">${EnableGamepadHelp}</div>
<div class="fieldDescription checkboxFieldDescription">${LabelPleaseRestart}</div>
</div>
</div>
<button is="emby-button" type="submit" class="raised button-submit block btnSave hide">
<span>${Save}</span>
</button>
</form>
</div>
</div>

View File

@ -0,0 +1,28 @@
import { Events } from 'jellyfin-apiclient';
import toast from '../../../components/toast/toast';
import globalize from '../../../scripts/globalize';
import appSettings from '../../../scripts/settings/appSettings';
export default function (view, params) {
function submit(e) {
appSettings.enableGamepad(view.querySelector('.chkEnableGamepad').checked);
toast(globalize.translate('SettingsSaved'));
Events.trigger(view, 'saved');
if (e) e.preventDefault();
return false;
}
view.addEventListener('viewshow', function () {
view.querySelector('.chkEnableGamepad').checked = appSettings.enableGamepad();
view.querySelector('form').addEventListener('submit', submit);
view.querySelector('.btnSave').classList.remove('hide');
import('../../../components/autoFocuser').then(({default: autoFocuser}) => {
autoFocuser.autoFocus(view);
});
});
}

View File

@ -66,6 +66,15 @@
</div>
</div>
</a>
<a is="emby-linkbutton" data-ripple="false" href="#" style="display:block;padding:0;margin:0;" class="lnkControlsPreferences listItem-border">
<div class="listItem">
<span class="material-icons listItemIcon listItemIcon-transparent keyboard"></span>
<div class="listItemBody">
<div class="listItemBodyText">${Controls}</div>
</div>
</div>
</a>
</div>
<div class="adminSection verticalSection verticalSection-extrabottompadding hide">
<h2 class="sectionTitle" style="padding-left:.25em;">${HeaderAdmin}</h2>

View File

@ -28,6 +28,7 @@ export default function (view, params) {
page.querySelector('.lnkPlaybackPreferences').setAttribute('href', '#!/mypreferencesplayback.html?userId=' + userId);
page.querySelector('.lnkSubtitlePreferences').setAttribute('href', '#!/mypreferencessubtitles.html?userId=' + userId);
page.querySelector('.lnkQuickConnectPreferences').setAttribute('href', '#!/mypreferencesquickconnect.html');
page.querySelector('.lnkControlsPreferences').setAttribute('href', '#!/mypreferencescontrols.html?userId=' + userId);
const supportsClientSettings = appHost.supports('clientsettings');
page.querySelector('.clientSettings').classList.toggle('hide', !supportsClientSettings);
@ -35,6 +36,8 @@ export default function (view, params) {
const supportsMultiServer = appHost.supports('multiserver');
page.querySelector('.selectServer').classList.toggle('hide', !supportsMultiServer);
page.querySelector('.lnkControlsPreferences').classList.toggle('hide', layoutManager.mobile);
ApiClient.getQuickConnect('Status')
.then(status => {
if (status !== 'Unavailable') {

View File

@ -5,6 +5,7 @@
import inputManager from './inputManager';
import layoutManager from '../components/layoutManager';
import appSettings from './settings/appSettings';
/**
* Key name mapping.
@ -160,7 +161,7 @@ function attachGamepadScript() {
}
// No need to check for gamepads manually at load time, the eventhandler will be fired for that
if (navigator.getGamepads) { /* eslint-disable-line compat/compat */
if (navigator.getGamepads && appSettings.enableGamepad()) { /* eslint-disable-line compat/compat */
window.addEventListener('gamepadconnected', attachGamepadScript);
}

View File

@ -84,6 +84,13 @@ import { appRouter } from '../components/appRouter';
controller: 'user/profile/index'
});
defineRoute({
alias: '/mypreferencescontrols.html',
path: 'user/controls/index.html',
autoFocus: false,
controller: 'user/controls/index'
});
defineRoute({
alias: '/mypreferencesdisplay.html',
path: 'user/display/index.html',

View File

@ -18,6 +18,19 @@ class AppSettings {
return this.get('enableAutoLogin') !== 'false';
}
/**
* Get or set 'Enable Gamepad' state.
* @param {boolean|undefined} val - Flag to enable 'Enable Gamepad' or undefined.
* @return {boolean} 'Enable Gamepad' state.
*/
enableGamepad(val) {
if (val !== undefined) {
return this.set('enableGamepad', val.toString());
}
return this.get('enableGamepad') === 'true';
}
enableSystemExternalPlayers(val) {
if (val !== undefined) {
this.set('enableSystemExternalPlayers', val.toString());

View File

@ -1507,5 +1507,8 @@
"MessagePlaybackError": "There was an error playing this file on your Google Cast receiver.",
"EnableEnhancedNvdecDecoder": "Enable enhanced NVDEC decoder",
"EnableVppTonemapping": "Enable VPP Tone mapping",
"AllowVppTonemappingHelp": "Full hardware based tone mapping without using OpenCL filter. Currently works only when transcoding videos with embedded HDR10 metadata."
"AllowVppTonemappingHelp": "Full hardware based tone mapping without using OpenCL filter. Currently works only when transcoding videos with embedded HDR10 metadata.",
"Controls": "Controls",
"LabelEnableGamepad": "Enable Gamepad",
"EnableGamepadHelp": "Listen for input from any connected controllers."
}