import { useState, useEffect } from 'react'; import { X, RefreshCw, Check, AlertCircle, Download, Loader2 } from 'lucide-react'; import { checkForUpdates, installUpdate } from '../utils/updater'; import { getVersion } from '@tauri-apps/api/app'; import { open } from '@tauri-apps/plugin-shell'; import { MiniParticleLogo } from './MiniParticleLogo'; import '../styles/AboutDialog.css'; interface AboutDialogProps { onClose: () => void; locale?: string; } export function AboutDialog({ onClose, locale = 'en' }: AboutDialogProps) { const [checking, setChecking] = useState(false); const [installing, setInstalling] = useState(false); const [updateStatus, setUpdateStatus] = useState<'idle' | 'checking' | 'available' | 'latest' | 'error' | 'installing'>('idle'); const [version, setVersion] = useState('1.0.0'); const [newVersion, setNewVersion] = useState(''); useEffect(() => { // Fetch version on mount const fetchVersion = async () => { try { const currentVersion = await getVersion(); setVersion(currentVersion); } catch (error) { console.error('Failed to get version:', error); } }; fetchVersion(); }, []); const t = (key: string) => { const translations: Record> = { en: { title: 'About ESEngine Editor', version: 'Version', description: 'High-performance game editor for ECS-based game development', checkUpdate: 'Check for Updates', checking: 'Checking...', updateAvailable: 'New version available', latest: 'You are using the latest version', error: 'Failed to check for updates', download: 'Download & Install', installing: 'Installing...', close: 'Close', copyright: '© 2025 ESEngine. All rights reserved.', website: 'Website', github: 'GitHub' }, zh: { title: '关于 ESEngine Editor', version: '版本', description: '高性能游戏编辑器,基于 ECS 架构', checkUpdate: '检查更新', checking: '检查中...', updateAvailable: '发现新版本', latest: '您正在使用最新版本', error: '检查更新失败', download: '下载并安装', installing: '正在安装...', close: '关闭', copyright: '© 2025 ESEngine. 保留所有权利。', website: '官网', github: 'GitHub' } }; return translations[locale]?.[key] || key; }; const handleCheckUpdate = async () => { setChecking(true); setUpdateStatus('checking'); try { const currentVersion = await getVersion(); setVersion(currentVersion); // 使用我们的 updater 工具检查更新(仅检查,不自动安装) const result = await checkForUpdates(); if (result.error) { setUpdateStatus('error'); } else if (result.available) { setUpdateStatus('available'); if (result.version) { setNewVersion(result.version); } } else { setUpdateStatus('latest'); } } catch (error) { console.error('Check update failed:', error); setUpdateStatus('error'); } finally { setChecking(false); } }; const handleInstallUpdate = async () => { setInstalling(true); setUpdateStatus('installing'); try { const success = await installUpdate(); if (!success) { setUpdateStatus('error'); setInstalling(false); } // 如果成功,应用会重启,不需要处理 } catch (error) { console.error('Install update failed:', error); setUpdateStatus('error'); setInstalling(false); } }; const getStatusIcon = () => { switch (updateStatus) { case 'checking': return ; case 'available': return ; case 'installing': return ; case 'latest': return ; case 'error': return ; default: return null; } }; const getStatusText = () => { switch (updateStatus) { case 'checking': return t('checking'); case 'available': return `${t('updateAvailable')} (v${newVersion})`; case 'installing': return t('installing'); case 'latest': return t('latest'); case 'error': return t('error'); default: return ''; } }; const handleOpenGithub = async () => { try { await open('https://github.com/esengine/ecs-framework'); } catch (error) { console.error('Failed to open GitHub link:', error); } }; return (
e.stopPropagation()}>

{t('title')}

ESEngine Editor

{t('version')}: Editor {version}

{t('description')}

{updateStatus !== 'idle' && (
{getStatusIcon()} {getStatusText()}
)} {updateStatus === 'available' && ( )}

{t('copyright')}

); }