'use client'; import { useEffect, useState } from 'react'; import { getCurrentWindow } from '@tauri-apps/api/window'; import { Minus, Square, X } from 'lucide-react'; import { cn } from '@/lib/utils'; import { useSystemHealth } from '@/hooks/use-system-health'; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'; export function TitleBar() { const [isMaximized, setIsMaximized] = useState(false); const health = useSystemHealth(); useEffect(() => { let isMounted = true; const checkMaximized = async () => { try { const appWindow = getCurrentWindow(); const maximized = await appWindow.isMaximized(); if (isMounted) { setIsMaximized(maximized); } } catch (error) { console.error('Failed to check window state:', error); } }; checkMaximized(); // Listener para mudanças de estado const setupListener = async () => { try { const appWindow = getCurrentWindow(); const unlisten = await appWindow.onResized(async () => { if (isMounted) { const maximized = await appWindow.isMaximized(); setIsMaximized(maximized); } }); return unlisten; } catch (error) { console.error('Failed to setup resize listener:', error); return null; } }; let unlistenFn: (() => void) | null = null; setupListener().then(fn => { unlistenFn = fn; }); return () => { isMounted = false; if (unlistenFn) { unlistenFn(); } }; }, []); const handleMinimize = async () => { const appWindow = getCurrentWindow(); await appWindow.minimize(); }; const handleMaximize = async () => { const appWindow = getCurrentWindow(); if (isMaximized) { await appWindow.unmaximize(); } else { await appWindow.maximize(); } }; const handleClose = async () => { const appWindow = getCurrentWindow(); await appWindow.close(); }; return (
{health.message}
RAM: {health.ram_percent.toFixed(1)}% | CPU: {health.cpu_percent.toFixed(1)}%