import { Carousel, DialogButton, Field, Focusable, ProgressBarWithInfo, Spinner, findSP, showModal } from '@decky/ui'; import { Suspense, lazy, useCallback, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { FaExclamation } from 'react-icons/fa'; import { VerInfo, checkForUpdates, doUpdate } from '../../../../updater'; import { useDeckyState } from '../../../DeckyState'; import InlinePatchNotes from '../../../patchnotes/InlinePatchNotes'; import WithSuspense from '../../../WithSuspense'; const MarkdownRenderer = lazy(() => import('../../../Markdown')); function PatchNotesModal({ versionInfo, closeModal }: { versionInfo: VerInfo | null; closeModal?: () => {} }) { const SP = findSP(); const { t } = useTranslation(); return ( <> (

{versionInfo?.all?.[id]?.name || 'Invalid Update Name'}

{versionInfo?.all?.[id]?.body ? ( {versionInfo.all[id].body} ) : ( t('Updater.no_patch_notes_desc') )}
)} fnGetId={(id) => id} nNumItems={versionInfo?.all?.length} nHeight={SP.innerHeight - 40} nItemHeight={SP.innerHeight - 40} nItemMarginX={0} initialColumn={0} autoFocus={true} fnGetColumnWidth={() => SP.innerWidth - SP.innerWidth * (10 / 100)} name={t('Updater.decky_updates') as string} />
); } export default function UpdaterSettings() { const { isLoaderUpdating, versionInfo, setVersionInfo } = useDeckyState(); const [checkingForUpdates, setCheckingForUpdates] = useState(false); const [updateProgress, setUpdateProgress] = useState(-1); const [reloading, setReloading] = useState(false); const { t } = useTranslation(); useEffect(() => { const a = DeckyBackend.addEventListener('updater/update_download_percentage', (percentage) => { setUpdateProgress(percentage); }); const b = DeckyBackend.addEventListener('updater/finish_download', () => { setUpdateProgress(0); setReloading(true); }); return () => { DeckyBackend.removeEventListener('updater/update_download_percentage', a); DeckyBackend.removeEventListener('updater/finish_download', b); }; }, []); const showPatchNotes = useCallback(() => { showModal(); }, [versionInfo]); return ( <> {t('Updater.updates.lat_version', { ver: versionInfo?.current })} ) } icon={ versionInfo?.remote && versionInfo?.remote?.tag_name != versionInfo?.current && ( ) } childrenContainerWidth={'fixed'} > {updateProgress == -1 && !isLoaderUpdating ? ( { setCheckingForUpdates(true); const verInfo = await checkForUpdates(); setVersionInfo(verInfo); setCheckingForUpdates(false); } : async () => { setUpdateProgress(0); doUpdate(); } } > {checkingForUpdates ? t('Updater.updates.checking') : !versionInfo?.remote || versionInfo?.remote?.tag_name == versionInfo?.current ? t('Updater.updates.check_button') : t('Updater.updates.install_button')} ) : ( )} {versionInfo?.remote && versionInfo?.remote?.tag_name != versionInfo?.current && ( }> {versionInfo?.remote.body} )} ); }