Inform about server version updates

This commit is contained in:
schroda
2024-05-07 01:35:19 +02:00
parent eb0ba0b6a8
commit 4f92a0130e
3 changed files with 78 additions and 22 deletions

View File

@@ -443,13 +443,14 @@
"info": "Server version {{version}} ({{channel}}) available for download", "info": "Server version {{version}} ({{channel}}) available for download",
"up_to_date": "This is the latest version", "up_to_date": "This is the latest version",
"update_failure": "Update failed", "update_failure": "Update failed",
"update_success": "{{name}} was updated to version {{version}} ({{channel}})",
"updating": "{{progress}}% | Updating…" "updating": "{{progress}}% | Updating…"
}, },
"settings": { "settings": {
"inform": { "inform": {
"label": { "label": {
"title": "Inform about available update", "description": "Shows a dialog in case a new version is available",
"description": "Shows a dialog in case a new version is available" "title": "Inform about available update"
} }
} }
} }
@@ -793,7 +794,6 @@
"github": "$t(global.label.github) $t(settings.webui.title.webui)", "github": "$t(global.label.github) $t(settings.webui.title.webui)",
"info": "$t(settings.webui.title.webui) version {{version}} ({{channel}}) available for download", "info": "$t(settings.webui.title.webui) version {{version}} ({{channel}}) available for download",
"update_failure": "Could not update $t(settings.webui.title.webui)", "update_failure": "Could not update $t(settings.webui.title.webui)",
"update_success": "Updated $t(settings.webui.title.webui) to version {{version}}.",
"updated": "Updated version", "updated": "Updated version",
"version": "$t(settings.webui.title.webui) version" "version": "$t(settings.webui.title.webui) version"
} }

View File

@@ -7,17 +7,28 @@
*/ */
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useState } from 'react';
import Dialog from '@mui/material/Dialog';
import DialogTitle from '@mui/material/DialogTitle';
import DialogContent from '@mui/material/DialogContent';
import DialogContentText from '@mui/material/DialogContentText';
import DialogActions from '@mui/material/DialogActions';
import Button from '@mui/material/Button';
import { requestManager } from '@/lib/requests/RequestManager.ts'; import { requestManager } from '@/lib/requests/RequestManager.ts';
import { getVersion } from '@/screens/settings/About.tsx'; import { getVersion } from '@/screens/settings/About.tsx';
import { useUpdateChecker } from '@/util/useUpdateChecker.tsx'; import { useUpdateChecker } from '@/util/useUpdateChecker.tsx';
import { VersionUpdateInfoDialog } from '@/components/util/VersionUpdateInfoDialog.tsx'; import { VersionUpdateInfoDialog } from '@/components/util/VersionUpdateInfoDialog.tsx';
import { useMetadataServerSettings } from '@/lib/metadata/metadataServerSettings.ts'; import { useMetadataServerSettings } from '@/lib/metadata/metadataServerSettings.ts';
import { useLocalStorage } from '@/util/useStorage.tsx';
const disabledUpdateCheck = () => Promise.resolve(); const disabledUpdateCheck = () => Promise.resolve();
export const ServerUpdateChecker = () => { export const ServerUpdateChecker = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const [serverVersion, setServerVersion] = useLocalStorage<string>('serverVersion');
const [open, setOpen] = useState(false);
const { const {
settings: { serverInformAvailableUpdate }, settings: { serverInformAvailableUpdate },
} = useMetadataServerSettings(); } = useMetadataServerSettings();
@@ -47,6 +58,16 @@ export const ServerUpdateChecker = () => {
selectedServerChannelInfo?.tag, selectedServerChannelInfo?.tag,
); );
const changelogUrl =
aboutServer?.buildType.toLowerCase() === 'stable'
? `https://github.com/Suwayomi/Suwayomi-Server/releases/tag/${aboutServer.version}`
: undefined;
const isSameAsCurrent = !version || serverVersion === version;
if (!isSameAsCurrent && !open) {
setOpen(true);
}
if (!serverInformAvailableUpdate) { if (!serverInformAvailableUpdate) {
return null; return null;
} }
@@ -59,28 +80,61 @@ export const ServerUpdateChecker = () => {
return null; return null;
} }
if (!isServerUpdateAvailable) { if (isServerUpdateAvailable) {
return null; const isAboutPage = window.location.pathname === '/settings/about';
if (isAboutPage) {
return null;
}
if (!updateChecker.handleUpdate) {
return null;
}
return (
<VersionUpdateInfoDialog
info={t('global.update.label.info', {
channel: selectedServerChannelInfo.channel,
version: selectedServerChannelInfo.tag,
})}
actionTitle={t('chapter.action.download.add.label.action')}
actionUrl={selectedServerChannelInfo.url}
updateCheckerProps={['server', checkForUpdate, selectedServerChannelInfo?.tag]}
/>
);
} }
const isAboutPage = window.location.pathname === '/settings/about'; if (!open) {
if (isAboutPage) {
return null;
}
if (!updateChecker.handleUpdate) {
return null; return null;
} }
return ( return (
<VersionUpdateInfoDialog <Dialog open={open}>
info={t('global.update.label.info', { <DialogTitle>{t('settings.about.webui.label.updated')}</DialogTitle>
channel: selectedServerChannelInfo.channel, <DialogContent>
version: selectedServerChannelInfo.tag, <DialogContentText>
})} {t('global.update.label.update_success', {
actionTitle={t('chapter.action.download.add.label.action')} name: t('settings.server.title.server'),
actionUrl={selectedServerChannelInfo.url} version,
updateCheckerProps={['server', checkForUpdate, selectedServerChannelInfo?.tag]} channel: aboutServer?.buildType,
/> })}
</DialogContentText>
</DialogContent>
<DialogActions>
{changelogUrl && (
<Button href={changelogUrl} target="_blank" rel="noreferrer">
{t('global.button.changelog')}
</Button>
)}
<Button
onClick={() => {
setServerVersion(version);
setOpen(false);
}}
variant="contained"
>
{t('global.button.ok')}
</Button>
</DialogActions>
</Dialog>
); );
}; };

View File

@@ -156,8 +156,10 @@ export const WebUIUpdateChecker = () => {
<DialogTitle>{t('settings.about.webui.label.updated')}</DialogTitle> <DialogTitle>{t('settings.about.webui.label.updated')}</DialogTitle>
<DialogContent> <DialogContent>
<DialogContentText> <DialogContentText>
{t('settings.about.webui.label.update_success', { {t('global.update.label.update_success', {
version: webUIVersion, name: t('settings.webui.title.webui'),
version: newVersion,
channel: aboutWebUI?.channel,
})} })}
</DialogContentText> </DialogContentText>
</DialogContent> </DialogContent>