diff --git a/web/src/features/modals/InfoModal.tsx b/web/src/features/modals/InfoModal.tsx index 435f24920c..b413e8fa97 100644 --- a/web/src/features/modals/InfoModal.tsx +++ b/web/src/features/modals/InfoModal.tsx @@ -8,12 +8,21 @@ import { VerticalDivider } from 'components/Divider'; import Modal from 'components/Modal'; import { useAtom } from 'jotai'; import { useTranslation } from 'react-i18next'; +import { useRegisterSW } from 'virtual:pwa-register/react'; import InfoText from './InfoText'; import { isInfoModalOpenAtom } from './modalAtoms'; export function InfoModalContent() { const { t } = useTranslation(); + const { + needRefresh: [needRefresh], + updateServiceWorker, + } = useRegisterSW(); + + const handleUpdate = () => { + updateServiceWorker(true); + }; return (
@@ -29,7 +38,18 @@ export function InfoModalContent() {
-

{t('info.version', { version: APP_VERSION })}

+
+

{t('info.version', { version: APP_VERSION })}

+ {needRefresh && ( + + )} +
); } diff --git a/web/src/features/service-worker/UpdatePrompt.tsx b/web/src/features/service-worker/UpdatePrompt.tsx index 6adf83d563..8d27c096aa 100644 --- a/web/src/features/service-worker/UpdatePrompt.tsx +++ b/web/src/features/service-worker/UpdatePrompt.tsx @@ -12,17 +12,23 @@ function UpdatePrompt() { updateServiceWorker, } = useRegisterSW({ onRegisteredSW: (_swURL, registration) => { - registration && - setInterval( - () => { - console.info(`Checking for app update...`); - registration.update(); - }, - import.meta.env.PROD ? ONE_HOUR : 10 * 1000 - ); + if (!registration) { + console.warn('Service Worker registration is null'); + return; + } + + setInterval( + () => { + console.info(`Checking for app update...`); + registration.update().catch((error) => { + console.error('Failed to update Service Worker:', error); + }); + }, + import.meta.env.PROD ? ONE_HOUR : 10 * 1000 + ); }, onRegisterError(error) { - console.error(`SW registration failed: ${error}`); + console.error('SW registration failed:', error); }, });