import { useEffect, useRef, useCallback } from "react"; import { openUrl } from "@tauri-apps/plugin-opener"; import type { UpdateInfo } from "../../lib/types"; interface Props { updateInfo: UpdateInfo; currentVersion: string; onDismiss: () => void; onClose: () => void; } export default function UpdateDialog({ updateInfo, currentVersion, onDismiss, onClose, }: Props) { const overlayRef = useRef(null); useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); }; document.addEventListener("keydown", handleKeyDown); return () => document.removeEventListener("keydown", handleKeyDown); }, [onClose]); const handleOverlayClick = useCallback( (e: React.MouseEvent) => { if (e.target === overlayRef.current) onClose(); }, [onClose], ); const handleDownload = async (url: string) => { try { await openUrl(url); } catch (e) { console.error("Failed to open URL:", e); } }; const formatSize = (bytes: number) => { if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(0)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; }; return (

Update Available

{currentVersion} {updateInfo.version}
{updateInfo.body && (

Release Notes

{updateInfo.body}
)} {updateInfo.assets.length > 0 && (

Downloads

{updateInfo.assets.map((asset) => ( ))}
)}
); }