/* * 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/. */ import { useTranslation } from 'react-i18next'; import { requestManager } from '@/lib/requests/RequestManager.ts'; import { getVersion } from '@/screens/settings/About.tsx'; import { useUpdateChecker } from '@/util/useUpdateChecker.tsx'; import { VersionUpdateInfoDialog } from '@/components/util/VersionUpdateInfoDialog.tsx'; export const ServerUpdateChecker = () => { const { t } = useTranslation(); const { data: serverUpdateCheckData, loading: isCheckingForServerUpdate, error: serverUpdateCheckError, refetch: checkForUpdate, } = requestManager.useCheckForServerUpdate({ notifyOnNetworkStatusChange: true, fetchPolicy: 'cache-only' }); const { data } = requestManager.useGetAbout(); const { aboutServer } = data ?? {}; const selectedServerChannelInfo = serverUpdateCheckData?.checkForServerUpdates?.find( (channel) => channel.channel === aboutServer?.buildType, ); const version = aboutServer ? getVersion(aboutServer) : undefined; const isServerUpdateAvailable = !!selectedServerChannelInfo?.tag && selectedServerChannelInfo.tag !== version; const updateChecker = useUpdateChecker('server', checkForUpdate, selectedServerChannelInfo?.tag); if (isCheckingForServerUpdate) { return null; } if (serverUpdateCheckError) { return null; } if (!isServerUpdateAvailable) { return null; } const isAboutPage = window.location.pathname === '/settings/about'; if (isAboutPage) { return null; } if (!updateChecker.handleUpdate) { return null; } return ( ); };