import React, { useEffect, useState } from 'react'; import Image from 'next/image'; import { useEnv } from '@/context/EnvContext'; import { useTranslation } from '@/hooks/useTranslation'; import { checkForAppUpdates, checkAppReleaseNotes } from '@/helpers/updater'; import { parseWebViewInfo } from '@/utils/ua'; import { getAppVersion } from '@/utils/version'; import SupportLinks from './SupportLinks'; import LegalLinks from './LegalLinks'; import Dialog from './Dialog'; import Link from './Link'; export const setAboutDialogVisible = (visible: boolean) => { const dialog = document.getElementById('about_window'); if (dialog) { const event = new CustomEvent('setDialogVisibility', { detail: { visible }, }); dialog.dispatchEvent(event); } }; type UpdateStatus = 'checking' | 'updating' | 'updated' | 'error'; export const AboutWindow = () => { const _ = useTranslation(); const { appService } = useEnv(); const [updateStatus, setUpdateStatus] = useState(null); const [browserInfo, setBrowserInfo] = useState(''); const [isOpen, setIsOpen] = useState(false); useEffect(() => { setBrowserInfo(parseWebViewInfo(appService)); const handleCustomEvent = (event: CustomEvent) => { setIsOpen(event.detail.visible); }; const el = document.getElementById('about_window'); if (el) { el.addEventListener('setDialogVisibility', handleCustomEvent as EventListener); } return () => { if (el) { el.removeEventListener('setDialogVisibility', handleCustomEvent as EventListener); } }; // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const handleCheckUpdate = async () => { setUpdateStatus('checking'); try { const hasUpdate = await checkForAppUpdates(_, false); if (hasUpdate) { handleClose(); } else { setUpdateStatus('updated'); } } catch (error) { console.info('Error checking for updates:', error); setUpdateStatus('error'); } }; const handleShowRecentUpdates = async () => { const hasNotes = await checkAppReleaseNotes(false); if (hasNotes) { handleClose(); } else { setUpdateStatus('error'); } }; const handleClose = () => { setIsOpen(false); setUpdateStatus(null); }; return ( {isOpen && (
App Logo

Readest

{_('Version {{version}}', { version: getAppVersion() })} {`(${browserInfo})`}

{!updateStatus && ( )} {updateStatus === 'updated' && (

{_('Already the latest version')}

)} {updateStatus === 'checking' && (

{_('Checking for updates...')}

)} {updateStatus === 'error' && (

{_('Error checking for updates')}

)}

© {new Date().getFullYear()} Bilingify LLC. All rights reserved.

This software is licensed under the{' '} GNU Affero General Public License v3.0 . You are free to use, modify, and distribute this software under the terms of the AGPL v3 license. Please see the license for more details.

Source code is available at{' '} GitHub .

)}
); };