2023-05-18 13:17:41 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2023-08-14 21:43:06 +02:00
|
|
|
import { useContext, useEffect } from 'react';
|
2021-09-09 17:51:22 +04:30
|
|
|
import List from '@mui/material/List';
|
|
|
|
|
import ListItem from '@mui/material/ListItem';
|
|
|
|
|
import ListItemText from '@mui/material/ListItemText';
|
2023-03-23 13:59:32 +01:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-11-27 19:14:43 +01:00
|
|
|
import ListSubheader from '@mui/material/ListSubheader';
|
2024-04-14 15:50:12 +02:00
|
|
|
import Button from '@mui/material/Button';
|
|
|
|
|
import CircularProgress from '@mui/material/CircularProgress';
|
|
|
|
|
import Divider from '@mui/material/Divider';
|
|
|
|
|
import Stack from '@mui/material/Stack';
|
|
|
|
|
import Typography from '@mui/material/Typography';
|
2023-12-09 23:08:27 +01:00
|
|
|
import RefreshIcon from '@mui/icons-material/Refresh';
|
|
|
|
|
import DownloadIcon from '@mui/icons-material/Download';
|
|
|
|
|
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
|
|
|
|
|
import { t as translate } from 'i18next';
|
|
|
|
|
import DownloadingIcon from '@mui/icons-material/Downloading';
|
2023-10-28 00:32:02 +02:00
|
|
|
import { requestManager } from '@/lib/requests/RequestManager.ts';
|
|
|
|
|
import { ListItemLink } from '@/components/util/ListItemLink';
|
2024-06-05 23:04:13 +02:00
|
|
|
import { NavBarContext } from '@/components/context/NavbarContext';
|
2023-10-28 00:32:02 +02:00
|
|
|
import { LoadingPlaceholder } from '@/components/util/LoadingPlaceholder';
|
2023-12-09 23:08:27 +01:00
|
|
|
import { GetAboutQuery, UpdateState } from '@/lib/graphql/generated/graphql.ts';
|
2023-12-31 01:42:54 +01:00
|
|
|
import { defaultPromiseErrorHandler } from '@/util/defaultPromiseErrorHandler.ts';
|
2024-04-29 15:29:33 +02:00
|
|
|
import { EmptyViewAbsoluteCentered } from '@/components/util/EmptyViewAbsoluteCentered.tsx';
|
2024-05-21 21:27:31 +02:00
|
|
|
import { epochToDate } from '@/util/date.ts';
|
2023-12-09 23:08:27 +01:00
|
|
|
|
|
|
|
|
type AboutServer = GetAboutQuery['aboutServer'];
|
|
|
|
|
|
2023-12-09 23:20:52 +01:00
|
|
|
export const getVersion = (aboutServer: AboutServer) => {
|
2023-12-09 23:08:27 +01:00
|
|
|
if (aboutServer.buildType === 'Stable') return `${aboutServer.version}`;
|
|
|
|
|
return `${aboutServer.version}-${aboutServer.revision}`;
|
|
|
|
|
};
|
|
|
|
|
|
2024-05-21 21:27:31 +02:00
|
|
|
const getBuildTime = (aboutServer: AboutServer) => epochToDate(Number(aboutServer.buildTime)).toString();
|
2023-12-09 23:08:27 +01:00
|
|
|
|
|
|
|
|
const getUpdateCheckButtonIcon = (
|
|
|
|
|
isLoading: boolean,
|
|
|
|
|
isUpdateAvailable: boolean,
|
|
|
|
|
updateState?: UpdateState,
|
|
|
|
|
asLink: boolean = false,
|
|
|
|
|
) => {
|
|
|
|
|
const isUpdateInProgress = updateState === UpdateState.Downloading;
|
|
|
|
|
if (isUpdateInProgress) {
|
|
|
|
|
return <DownloadingIcon />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
|
return <CircularProgress size={15} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isRefreshRequired = !isUpdateAvailable || updateState === UpdateState.Error;
|
|
|
|
|
if (isRefreshRequired) {
|
|
|
|
|
return <RefreshIcon />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return asLink ? <OpenInNewIcon /> : <DownloadIcon />;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const getUpdateCheckButtonText = (
|
|
|
|
|
isLoading: boolean,
|
|
|
|
|
isUpdateAvailable: boolean,
|
|
|
|
|
error: any,
|
|
|
|
|
updateState?: UpdateState,
|
|
|
|
|
progress: number = 0,
|
|
|
|
|
) => {
|
|
|
|
|
const isUpdating = updateState === UpdateState.Downloading;
|
|
|
|
|
if (isUpdating) {
|
|
|
|
|
return translate('global.update.label.updating', { progress });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const didUpdateFail = updateState === UpdateState.Error;
|
|
|
|
|
if (didUpdateFail) {
|
|
|
|
|
return translate('global.update.label.update_failure');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
|
return translate('global.update.label.checking');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (error) {
|
|
|
|
|
return translate('global.update.label.check_failure');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isUpdateAvailable) {
|
|
|
|
|
return translate('global.update.label.available');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return translate('global.update.label.up_to_date');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type BaseVersionInfoProps = {
|
|
|
|
|
version: string;
|
|
|
|
|
isCheckingForUpdate: boolean;
|
|
|
|
|
isUpdateAvailable: boolean;
|
|
|
|
|
updateCheckError: any;
|
|
|
|
|
checkForUpdate: () => void;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type LinkVersionInfoProps = {
|
|
|
|
|
downloadAsLink: true;
|
|
|
|
|
url: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type TriggerVersionInfoProps = {
|
|
|
|
|
triggerUpdate: () => void;
|
|
|
|
|
updateState: UpdateState;
|
|
|
|
|
progress: number;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
type VersionInfoProps =
|
|
|
|
|
| (BaseVersionInfoProps & PropertiesNever<TriggerVersionInfoProps> & LinkVersionInfoProps)
|
|
|
|
|
| (BaseVersionInfoProps & TriggerVersionInfoProps & PropertiesNever<LinkVersionInfoProps>);
|
|
|
|
|
|
|
|
|
|
const VersionInfo = ({
|
|
|
|
|
version,
|
|
|
|
|
isCheckingForUpdate,
|
|
|
|
|
isUpdateAvailable,
|
|
|
|
|
updateCheckError,
|
|
|
|
|
checkForUpdate,
|
|
|
|
|
triggerUpdate,
|
|
|
|
|
updateState,
|
|
|
|
|
progress,
|
|
|
|
|
downloadAsLink,
|
|
|
|
|
url,
|
|
|
|
|
}: VersionInfoProps) => {
|
|
|
|
|
const isUpdateInProgress = updateState === UpdateState.Downloading;
|
|
|
|
|
|
|
|
|
|
const onClick = () => {
|
|
|
|
|
if (isUpdateInProgress) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const shouldCheckForUpdate = !isUpdateAvailable || updateCheckError || updateState === UpdateState.Error;
|
|
|
|
|
if (shouldCheckForUpdate) {
|
|
|
|
|
checkForUpdate();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isUpdateAvailable) {
|
|
|
|
|
triggerUpdate?.();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2024-09-03 17:15:47 +02:00
|
|
|
<Stack
|
|
|
|
|
sx={{
|
|
|
|
|
alignItems: 'start',
|
|
|
|
|
}}
|
|
|
|
|
>
|
2023-12-09 23:08:27 +01:00
|
|
|
<Typography component="span" variant="body2">
|
|
|
|
|
{version}
|
|
|
|
|
</Typography>
|
|
|
|
|
<Button
|
|
|
|
|
sx={{
|
|
|
|
|
marginTop: '5px',
|
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
|
pointerEvents: isUpdateInProgress ? 'none' : 'unset',
|
|
|
|
|
}}
|
|
|
|
|
size="small"
|
|
|
|
|
variant="outlined"
|
|
|
|
|
startIcon={getUpdateCheckButtonIcon(
|
|
|
|
|
isCheckingForUpdate,
|
|
|
|
|
isUpdateAvailable,
|
|
|
|
|
updateState,
|
|
|
|
|
downloadAsLink,
|
|
|
|
|
)}
|
|
|
|
|
onClick={onClick}
|
|
|
|
|
{...(!!url && isUpdateAvailable
|
|
|
|
|
? {
|
|
|
|
|
href: url,
|
|
|
|
|
target: '_blank',
|
|
|
|
|
}
|
|
|
|
|
: undefined)}
|
|
|
|
|
>
|
|
|
|
|
{getUpdateCheckButtonText(
|
|
|
|
|
isCheckingForUpdate,
|
|
|
|
|
isUpdateAvailable,
|
|
|
|
|
updateCheckError,
|
|
|
|
|
updateState,
|
|
|
|
|
progress,
|
|
|
|
|
)}
|
|
|
|
|
</Button>
|
|
|
|
|
</Stack>
|
|
|
|
|
);
|
|
|
|
|
};
|
2021-05-25 21:06:27 +04:30
|
|
|
|
2023-10-28 00:32:02 +02:00
|
|
|
export function About() {
|
2023-03-23 13:59:32 +01:00
|
|
|
const { t } = useTranslation();
|
2023-10-28 00:32:02 +02:00
|
|
|
const { setTitle, setAction } = useContext(NavBarContext);
|
2021-05-25 21:06:27 +04:30
|
|
|
|
2023-02-06 10:06:33 +01:00
|
|
|
useEffect(() => {
|
2023-03-23 13:59:32 +01:00
|
|
|
setTitle(t('settings.about.title'));
|
2023-03-11 18:05:58 +01:00
|
|
|
setAction(null);
|
2024-01-26 20:50:51 +01:00
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
setTitle('');
|
|
|
|
|
setAction(null);
|
|
|
|
|
};
|
2023-03-28 23:14:03 +02:00
|
|
|
}, [t]);
|
2021-05-25 21:06:27 +04:30
|
|
|
|
2024-04-27 22:28:55 +02:00
|
|
|
const { data, loading, error, refetch } = requestManager.useGetAbout({ notifyOnNetworkStatusChange: true });
|
2021-05-25 21:06:27 +04:30
|
|
|
|
2023-12-09 23:08:27 +01:00
|
|
|
const {
|
|
|
|
|
data: serverUpdateCheckData,
|
|
|
|
|
loading: isCheckingForServerUpdate,
|
|
|
|
|
refetch: checkForServerUpdate,
|
|
|
|
|
error: serverUpdateCheckError,
|
|
|
|
|
} = requestManager.useCheckForServerUpdate({ notifyOnNetworkStatusChange: true });
|
|
|
|
|
const {
|
|
|
|
|
data: webUIUpdateData,
|
|
|
|
|
loading: isCheckingForWebUIUpdate,
|
|
|
|
|
refetch: checkForWebUIUpdate,
|
|
|
|
|
error: orgWebUIUpdateCheckError,
|
|
|
|
|
} = requestManager.useCheckForWebUIUpdate({ notifyOnNetworkStatusChange: true });
|
|
|
|
|
const webUIUpdateCheckError = orgWebUIUpdateCheckError || webUIUpdateData?.checkForWebUIUpdate.tag === '';
|
|
|
|
|
|
2024-01-01 22:40:39 +01:00
|
|
|
const { data: webUIUpdateStatusData } = requestManager.useGetWebUIUpdateStatus();
|
|
|
|
|
const { state: webUIUpdateState, progress: webUIUpdateProgress } = webUIUpdateStatusData?.getWebUIUpdateStatus ?? {
|
|
|
|
|
state: UpdateState.Idle,
|
|
|
|
|
progress: 0,
|
|
|
|
|
};
|
2023-12-09 23:08:27 +01:00
|
|
|
|
2024-04-27 16:24:55 +02:00
|
|
|
if (loading) {
|
|
|
|
|
return <LoadingPlaceholder />;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-27 22:28:55 +02:00
|
|
|
if (error) {
|
|
|
|
|
return (
|
2024-04-29 15:29:33 +02:00
|
|
|
<EmptyViewAbsoluteCentered
|
2024-04-27 22:28:55 +02:00
|
|
|
message={t('global.error.label.failed_to_load_data')}
|
|
|
|
|
messageExtra={error.message}
|
|
|
|
|
retry={() => refetch().catch(defaultPromiseErrorHandler('About::refetch'))}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-05 00:36:16 +02:00
|
|
|
const { aboutServer, aboutWebUI } = data!;
|
|
|
|
|
const selectedServerChannelInfo = serverUpdateCheckData?.checkForServerUpdates?.find(
|
|
|
|
|
(channel) => channel.channel === aboutServer.buildType,
|
|
|
|
|
);
|
|
|
|
|
const isServerUpdateAvailable =
|
|
|
|
|
!!selectedServerChannelInfo?.tag && selectedServerChannelInfo.tag !== getVersion(aboutServer);
|
|
|
|
|
const isWebUIUpdateAvailable = !!webUIUpdateData?.checkForWebUIUpdate.updateAvailable;
|
|
|
|
|
|
2021-05-25 21:06:27 +04:30
|
|
|
return (
|
2024-09-05 00:34:13 +02:00
|
|
|
<List sx={{ pt: 0 }}>
|
2023-11-27 19:14:43 +01:00
|
|
|
<List
|
|
|
|
|
sx={{ padding: 0 }}
|
|
|
|
|
subheader={
|
|
|
|
|
<ListSubheader component="div" id="about-server-info">
|
|
|
|
|
{t('settings.server.title.server')}
|
|
|
|
|
</ListSubheader>
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<ListItem>
|
|
|
|
|
<ListItemText
|
|
|
|
|
primary={t('settings.server.title.server')}
|
|
|
|
|
secondary={`${aboutServer.name} ${aboutServer.buildType}`}
|
|
|
|
|
/>
|
|
|
|
|
</ListItem>
|
|
|
|
|
<ListItem>
|
2023-12-09 23:08:27 +01:00
|
|
|
<ListItemText
|
|
|
|
|
primary={t('settings.about.server.label.version')}
|
|
|
|
|
secondary={
|
|
|
|
|
<VersionInfo
|
|
|
|
|
version={getVersion(aboutServer)}
|
|
|
|
|
isCheckingForUpdate={isCheckingForServerUpdate}
|
|
|
|
|
isUpdateAvailable={isServerUpdateAvailable}
|
|
|
|
|
updateCheckError={serverUpdateCheckError}
|
|
|
|
|
checkForUpdate={checkForServerUpdate}
|
|
|
|
|
downloadAsLink
|
|
|
|
|
url={selectedServerChannelInfo?.url ?? ''}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
/>
|
2023-11-27 19:14:43 +01:00
|
|
|
</ListItem>
|
|
|
|
|
<ListItem>
|
2023-12-09 23:08:27 +01:00
|
|
|
<ListItemText
|
|
|
|
|
primary={t('settings.about.server.label.build_time')}
|
|
|
|
|
secondary={getBuildTime(aboutServer)}
|
|
|
|
|
/>
|
2023-11-27 19:14:43 +01:00
|
|
|
</ListItem>
|
|
|
|
|
</List>
|
|
|
|
|
<Divider />
|
|
|
|
|
<List
|
|
|
|
|
sx={{ padding: 0 }}
|
|
|
|
|
subheader={
|
|
|
|
|
<ListSubheader component="div" id="about-webui-info">
|
|
|
|
|
{t('settings.webui.title.webui')}
|
|
|
|
|
</ListSubheader>
|
|
|
|
|
}
|
|
|
|
|
>
|
2024-04-21 12:51:08 +02:00
|
|
|
<ListItem>
|
|
|
|
|
<ListItemText
|
|
|
|
|
primary={t('settings.about.webui.label.channel')}
|
|
|
|
|
secondary={aboutWebUI.channel.toLocaleUpperCase()}
|
|
|
|
|
/>
|
|
|
|
|
</ListItem>
|
2023-11-27 19:14:43 +01:00
|
|
|
<ListItem>
|
2023-12-09 23:08:27 +01:00
|
|
|
<ListItemText
|
|
|
|
|
primary={t('settings.about.webui.label.version')}
|
|
|
|
|
secondary={
|
|
|
|
|
<VersionInfo
|
|
|
|
|
version={aboutWebUI.tag}
|
|
|
|
|
isCheckingForUpdate={isCheckingForWebUIUpdate}
|
|
|
|
|
isUpdateAvailable={isWebUIUpdateAvailable}
|
|
|
|
|
updateCheckError={webUIUpdateCheckError}
|
|
|
|
|
checkForUpdate={checkForWebUIUpdate}
|
2023-12-31 01:42:54 +01:00
|
|
|
triggerUpdate={() =>
|
|
|
|
|
requestManager
|
|
|
|
|
.updateWebUI()
|
|
|
|
|
.response.catch(defaultPromiseErrorHandler('About::updateWebUI'))
|
|
|
|
|
}
|
2023-12-09 23:08:27 +01:00
|
|
|
progress={webUIUpdateProgress}
|
|
|
|
|
updateState={webUIUpdateState}
|
|
|
|
|
/>
|
|
|
|
|
}
|
|
|
|
|
/>
|
2023-11-27 19:14:43 +01:00
|
|
|
</ListItem>
|
|
|
|
|
</List>
|
|
|
|
|
<Divider />
|
|
|
|
|
<List
|
|
|
|
|
subheader={
|
|
|
|
|
<ListSubheader component="div" id="about-links">
|
|
|
|
|
{t('global.label.links')}
|
|
|
|
|
</ListSubheader>
|
|
|
|
|
}
|
|
|
|
|
>
|
2024-05-04 23:54:33 +02:00
|
|
|
<ListItemLink to={aboutServer.github} target="_blank" rel="noreferrer">
|
2023-11-27 19:14:43 +01:00
|
|
|
<ListItemText primary={t('settings.about.server.label.github')} secondary={aboutServer.github} />
|
|
|
|
|
</ListItemLink>
|
2024-05-04 23:54:33 +02:00
|
|
|
<ListItemLink to="https://github.com/Suwayomi/Suwayomi-WebUI" target="_blank" rel="noreferrer">
|
2023-11-27 19:14:43 +01:00
|
|
|
<ListItemText
|
|
|
|
|
primary={t('settings.about.webui.label.github')}
|
2024-01-05 20:11:29 +01:00
|
|
|
secondary="https://github.com/Suwayomi/Suwayomi-WebUI"
|
2023-11-27 19:14:43 +01:00
|
|
|
/>
|
|
|
|
|
</ListItemLink>
|
2024-05-04 23:54:33 +02:00
|
|
|
<ListItemLink to={aboutServer.discord} target="_blank" rel="noreferrer">
|
2023-11-27 19:14:43 +01:00
|
|
|
<ListItemText primary={t('global.label.discord')} secondary={aboutServer.discord} />
|
|
|
|
|
</ListItemLink>
|
|
|
|
|
</List>
|
2021-05-25 21:06:27 +04:30
|
|
|
</List>
|
|
|
|
|
);
|
|
|
|
|
}
|