1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

Additional code review

This commit is contained in:
Nick 2024-03-23 09:31:07 -07:00
parent 55d57eedcc
commit 5a9378012c
2 changed files with 26 additions and 10 deletions

View file

@ -11,6 +11,7 @@ import InputElement from '../../../../elements/InputElement';
import LinkTrickplayAcceleration from '../../../../components/dashboard/playback/trickplay/LinkTrickplayAcceleration';
import loading from '../../../../components/loading/loading';
import toast from '../../../../components/toast/toast';
import ServerConnections from '../../../../components/ServerConnections';
function onSaveComplete() {
loading.hide();
@ -46,10 +47,10 @@ const PlaybackTrickplay: FunctionComponent = () => {
const loadData = useCallback(() => {
loading.show();
window.ApiClient.getServerConfiguration().then(function (config) {
ServerConnections.currentApiClient()?.getServerConfiguration().then(function (config) {
loadConfig(config);
}).catch(err => {
console.error('[playbacktrickplay] failed to fetch server config', err);
console.error('[PlaybackTrickplay] failed to fetch server config', err);
});
}, [loadConfig]);
@ -62,6 +63,13 @@ const PlaybackTrickplay: FunctionComponent = () => {
}
const saveConfig = (config: ServerConfiguration) => {
const apiClient = ServerConnections.currentApiClient();
if (!apiClient) {
console.error('[PlaybackTrickplay] No current apiclient instance');
return;
}
if (!config.TrickplayOptions) {
throw new Error('Unexpected null TrickplayOptions');
}
@ -78,20 +86,26 @@ const PlaybackTrickplay: FunctionComponent = () => {
options.JpegQuality = Math.min(100, parseInt((page.querySelector('#txtJpegQuality') as HTMLInputElement).value || '90', 10));
options.ProcessThreads = parseInt((page.querySelector('#txtProcessThreads') as HTMLInputElement).value || '1', 10);
window.ApiClient.updateServerConfiguration(config).then(() => {
apiClient.updateServerConfiguration(config).then(() => {
onSaveComplete();
}).catch(err => {
console.error('[playbacktrickplay] failed to update config', err);
console.error('[PlaybackTrickplay] failed to update config', err);
});
};
const onSubmit = (e: Event) => {
loading.show();
const apiClient = ServerConnections.currentApiClient();
window.ApiClient.getServerConfiguration().then(function (config) {
if (!apiClient) {
console.error('[PlaybackTrickplay] No current apiclient instance');
return;
}
loading.show();
apiClient.getServerConfiguration().then(function (config) {
saveConfig(config);
}).catch(err => {
console.error('[playbacktrickplay] failed to fetch server config', err);
console.error('[PlaybackTrickplay] failed to fetch server config', err);
});
e.preventDefault();

View file

@ -151,15 +151,17 @@ export default function (view) {
trickplayResolution = null;
const mediaSourceId = currentPlayer.streamInfo.mediaSource.Id;
let trickplayResolutions;
if (item.Trickplay && (trickplayResolutions = item.Trickplay[mediaSourceId])) {
const trickplayResolutions = item.Trickplay?.[mediaSourceId];
if (trickplayResolutions) {
// Prefer highest resolution <= 20% of total screen resolution width
let bestWidth;
const maxWidth = window.screen.width * window.devicePixelRatio * 0.2;
for (const [, info] of Object.entries(trickplayResolutions)) {
if (!bestWidth
|| (info.Width < bestWidth && bestWidth > maxWidth) // Objects not guaranteed to be sorted in any order, first width might be > maxWidth.
|| (info.Width > bestWidth && info.Width <= maxWidth)) bestWidth = info.Width;
|| (info.Width > bestWidth && info.Width <= maxWidth)) {
bestWidth = info.Width;
}
}
if (bestWidth) trickplayResolution = trickplayResolutions[bestWidth];