refactor: optimize system health monitoring and UI interactions
- Removed unnecessary delay in chat redirection for immediate user feedback. - Enhanced TitleBar component with a system health indicator, displaying RAM and CPU usage. - Implemented optimistic UI updates for model downloads and Ollama installation, improving responsiveness. - Introduced background health monitoring to prevent resource overload during operations. - Added cleanup logic for child processes to ensure proper resource management during application shutdown.
This commit is contained in:
1 parent
c7da6cb8a8
commit
bd1e3ca2e6
7 files changed
+695
-89
No files matched your search
@@ -115,19 +115,21 @@ export function ModelSelector({ recommendation, onComplete }: ModelSelectorProps
|
||||
};
|
||||
|
||||
const handleDownload = async () => {
|
||||
// Optimistic UI: atualizar estado imediatamente antes da chamada Tauri
|
||||
setIsDownloading(true);
|
||||
setDownloadProgress(0);
|
||||
setDownloadStatus("Iniciando download...");
|
||||
try {
|
||||
await invoke('pull_model', { name: selectedModelId });
|
||||
// O status será atualizado pelo listener quando o download completar
|
||||
// Não precisamos setar aqui pois o listener já faz isso
|
||||
} catch (error) {
|
||||
console.error("Download failed", error);
|
||||
setDownloadStatus("Falha no download. Tente novamente.");
|
||||
setDownloadProgress(0);
|
||||
setIsDownloading(false);
|
||||
}
|
||||
|
||||
// Chamar Tauri em background (não bloquear)
|
||||
invoke('pull_model', { name: selectedModelId })
|
||||
.catch((error) => {
|
||||
console.error("Download failed", error);
|
||||
setDownloadStatus("Falha no download. Tente novamente.");
|
||||
setDownloadProgress(0);
|
||||
setIsDownloading(false);
|
||||
});
|
||||
// O status será atualizado pelo listener quando o download completar
|
||||
// Não precisamos aguardar aqui pois o listener já faz isso
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -4,9 +4,12 @@ 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;
|
||||
@@ -94,6 +97,28 @@ export function TitleBar() {
|
||||
<span className="text-sm font-medium text-sidebar-foreground">
|
||||
OllaHub
|
||||
</span>
|
||||
|
||||
{/* Indicador de saúde do sistema */}
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<div
|
||||
className={cn(
|
||||
"w-2 h-2 rounded-full shrink-0",
|
||||
health.status === 'healthy' && "bg-green-500",
|
||||
health.status === 'warning' && "bg-yellow-500",
|
||||
health.status === 'critical' && "bg-red-500"
|
||||
)}
|
||||
/>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent side="bottom" className="text-xs">
|
||||
<p>{health.message}</p>
|
||||
<p className="text-muted-foreground mt-1">
|
||||
RAM: {health.ram_percent.toFixed(1)}% | CPU: {health.cpu_percent.toFixed(1)}%
|
||||
</p>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
</TooltipProvider>
|
||||
</div>
|
||||
|
||||
{/* Controles de janela */}
|
||||
|
||||
Reference in new issue
Block a user