diff --git a/src/components/update/index.tsx b/src/components/update/index.tsx index 60d179877..004a644a4 100644 --- a/src/components/update/index.tsx +++ b/src/components/update/index.tsx @@ -14,10 +14,48 @@ import { Progress } from '@/components/ui/progress'; import type { ProgressInfo } from 'electron-updater'; +import { Package, X } from 'lucide-react'; import { useCallback, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { toast } from 'sonner'; +interface UpdateToastProps { + toastId: string | number; + children: React.ReactNode; + onClose?: () => void; +} + +const UpdateToastShell = ({ toastId, children, onClose }: UpdateToastProps) => { + const { t } = useTranslation(); + + return ( +
+
+
+ + + {t('update.update-eigent')} + +
+ +
+ {children} +
+ ); +}; + +// ── Main component ────────────────────────────────────────────────── const Update = () => { const [downloadProgress, setDownloadProgress] = useState(0); const [isDownloading, setIsDownloading] = useState(false); @@ -30,18 +68,39 @@ const Update = () => { const onUpdateCanAvailable = useCallback( (_event: Electron.IpcRendererEvent, info: VersionInfo) => { if (info.update) { - toast(t('update.new-version-available'), { - description: `v${info.version} → v${info.newVersion}`, - action: { - label: t('update.download'), - onClick: () => { - setIsDownloading(true); - setDownloadProgress(0); - window.ipcRenderer.invoke('start-download'); - }, - }, - duration: Infinity, - }); + toast.custom( + (toastId) => ( + +
+

+ {t('update.new-version-available')} +

+

+ v{info.version} → v{info.newVersion} +

+ +
+
+ ), + { id: 'update-available', duration: Infinity } + ); } }, [t] @@ -58,7 +117,6 @@ const Update = () => { const onDownloadProgress = useCallback( (_event: Electron.IpcRendererEvent, progress: ProgressInfo) => { - console.log('Download progress received:', progress); setDownloadProgress(progress.percent ?? 0); }, [] @@ -68,37 +126,68 @@ const Update = () => { useEffect(() => { if (isDownloading) { toast.custom( - (_toastId) => ( -
-
- {t('update.downloading-update')} + (toastId) => ( + { + setIsDownloading(false); + }} + > +
{ + setIsDownloading(false); + toast.dismiss(toastId); + }} + > + + {t('update.downloading-in-progress')} + + + {t('update.click-to-stop')} +
- -
- {Math.round(downloadProgress)}% {t('update.complete')} -
-
+ + ), - { - id: 'download-progress', - duration: Infinity, - } + { id: 'download-progress', duration: Infinity } ); } }, [downloadProgress, isDownloading, t]); const onUpdateDownloaded = useCallback( (_event: Electron.IpcRendererEvent) => { - toast.dismiss('download-progress'); setIsDownloading(false); - toast.success(t('update.download-completed'), { - description: t('update.click-to-install-update'), - action: { - label: t('update.install'), - onClick: () => window.ipcRenderer.invoke('quit-and-install'), - }, - duration: Infinity, - }); + toast.dismiss('download-progress'); + + toast.custom( + (toastId) => ( + +
+ + {t('update.ready-to-install')} + + window.ipcRenderer.invoke('quit-and-install')} + > + {t('update.click-to-restart')} + +
+
+ ), + { id: 'update-downloaded', duration: Infinity } + ); }, [t] ); diff --git a/src/i18n/locales/en-us/update.json b/src/i18n/locales/en-us/update.json index d3b8004ab..77868ad34 100644 --- a/src/i18n/locales/en-us/update.json +++ b/src/i18n/locales/en-us/update.json @@ -7,5 +7,10 @@ "complete": "Complete", "download-completed": "Download completed", "click-to-install-update": "Click to install update", - "install": "Install" + "install": "Install", + "update-eigent": "Update Eigent", + "downloading-in-progress": "Downloading in progress.", + "click-to-stop": "Click to stop.", + "ready-to-install": "Ready to install.", + "click-to-restart": "Click to restart." }