mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2026-09-03 03:50:02 +03:00
Add display version util for 12.0
This commit is contained in:
@@ -10,6 +10,7 @@ import RefreshIcon from '@mui/icons-material/Refresh';
|
||||
import RestartAltIcon from '@mui/icons-material/RestartAlt';
|
||||
import PowerSettingsNewIcon from '@mui/icons-material/PowerSettingsNew';
|
||||
import { useSystemInfo } from 'hooks/useSystemInfo';
|
||||
import { getDisplayVersion } from 'utils/versions';
|
||||
|
||||
type ServerInfoWidgetProps = {
|
||||
onScanLibrariesClick?: () => void;
|
||||
@@ -26,6 +27,9 @@ const ServerInfoWidget = ({
|
||||
}: ServerInfoWidgetProps) => {
|
||||
const { data: systemInfo, isPending } = useSystemInfo();
|
||||
|
||||
const displayServerVersion = getDisplayVersion(systemInfo?.Version);
|
||||
const displayWebVersion = getDisplayVersion(__PACKAGE_JSON_VERSION__);
|
||||
|
||||
return (
|
||||
<Widget
|
||||
title={globalize.translate('TabServer')}
|
||||
@@ -43,21 +47,21 @@ const ServerInfoWidget = ({
|
||||
<Typography fontWeight='bold'>{globalize.translate('LabelBuildVersion')}</Typography>
|
||||
</Stack>
|
||||
<Stack flexGrow={5} spacing={1}>
|
||||
{isPending ? (
|
||||
<>
|
||||
<Skeleton />
|
||||
<Skeleton />
|
||||
<Skeleton />
|
||||
<Skeleton />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Typography>{systemInfo?.ServerName}</Typography>
|
||||
<Typography>{systemInfo?.Version}</Typography>
|
||||
<Typography>{__PACKAGE_JSON_VERSION__}</Typography>
|
||||
<Typography>{__JF_BUILD_VERSION__}</Typography>
|
||||
</>
|
||||
)}
|
||||
<>
|
||||
{isPending ? (
|
||||
<>
|
||||
<Skeleton />
|
||||
<Skeleton />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Typography>{systemInfo?.ServerName}</Typography>
|
||||
<Typography>{displayServerVersion}</Typography>
|
||||
</>
|
||||
)}
|
||||
<Typography>{displayWebVersion}</Typography>
|
||||
<Typography>{__JF_BUILD_VERSION__}</Typography>
|
||||
</>
|
||||
</Stack>
|
||||
</Stack>
|
||||
</Paper>
|
||||
|
||||
@@ -6,10 +6,10 @@ import { ApiClient } from 'jellyfin-apiclient';
|
||||
import events from 'utils/events';
|
||||
import { ajax } from 'utils/fetch';
|
||||
import { equalsIgnoreCase } from 'utils/string';
|
||||
import { compareVersions } from 'utils/versions';
|
||||
|
||||
import { ConnectionMode } from './connectionMode';
|
||||
import { ConnectionState } from './connectionState';
|
||||
import { compareVersions } from './utils/compareVersions';
|
||||
|
||||
const DEFAULT_CONNECTION_TIMEOUT = 20000;
|
||||
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
export function compareVersions(a: string = '', b: string = '') {
|
||||
// -1 a is smaller
|
||||
// 1 a is larger
|
||||
// 0 equal
|
||||
const aParts = a.split('.');
|
||||
const bParts = b.split('.');
|
||||
|
||||
for (let i = 0, length = Math.max(aParts.length, bParts.length); i < length; i++) {
|
||||
const aVal = parseInt(aParts[i] || '0', 10);
|
||||
const bVal = parseInt(bParts[i] || '0', 10);
|
||||
|
||||
if (aVal < bVal) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (aVal > bVal) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { compareVersions, getDisplayVersion } from './versions';
|
||||
|
||||
describe('compareVersions', () => {
|
||||
it('should return 0 for equal versions', () => {
|
||||
expect(compareVersions('1.2.3', '1.2.3')).toBe(0);
|
||||
});
|
||||
|
||||
it('should return -1 when the first version is lower', () => {
|
||||
expect(compareVersions('1.2.3', '1.2.4')).toBe(-1);
|
||||
expect(compareVersions('1.2.3', '1.3.0')).toBe(-1);
|
||||
expect(compareVersions('1.2.3', '2')).toBe(-1);
|
||||
});
|
||||
|
||||
it('should return 1 when the first version is higher', () => {
|
||||
expect(compareVersions('1.2.4', '1.2.3')).toBe(1);
|
||||
expect(compareVersions('1.3.0', '1.2.3')).toBe(1);
|
||||
expect(compareVersions('2', '1.2.3')).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getDisplayVersion', () => {
|
||||
it('should return undefined for null or undefined input', () => {
|
||||
expect(getDisplayVersion(null)).toBeUndefined();
|
||||
expect(getDisplayVersion(undefined)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return the full version for versions below 11.0.0', () => {
|
||||
expect(getDisplayVersion('10.11.6')).toBe('10.11.6');
|
||||
});
|
||||
|
||||
it('should return only major.minor for versions above 10.0.0', () => {
|
||||
expect(getDisplayVersion('11.0.0')).toBe('11.0');
|
||||
expect(getDisplayVersion('12.3.4')).toBe('12.3');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Compares two version strings (e.g., "1.2.3") and returns:
|
||||
* -1 if a < b
|
||||
* 1 if a > b
|
||||
* 0 if a == b
|
||||
*/
|
||||
export function compareVersions(a: string = '', b: string = '') {
|
||||
const aParts = a.split('.');
|
||||
const bParts = b.split('.');
|
||||
|
||||
for (let i = 0, length = Math.max(aParts.length, bParts.length); i < length; i++) {
|
||||
const aVal = parseInt(aParts[i] || '0', 10);
|
||||
const bVal = parseInt(bParts[i] || '0', 10);
|
||||
|
||||
if (aVal < bVal) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (aVal > bVal) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Formats a version (e.g., "1.2.3") string for display. */
|
||||
export function getDisplayVersion(version: string | null | undefined) {
|
||||
if (!version) return;
|
||||
|
||||
// For versions above 10.X, we switch to only showing major.minor to reflect the new versioning scheme.
|
||||
if (compareVersions(version, '11') >= 0) {
|
||||
return version.split('.').slice(0, 2).join('.');
|
||||
}
|
||||
|
||||
return version;
|
||||
};
|
||||
Reference in New Issue
Block a user