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
@@ -0,0 +1,53 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from 'react';
|
||||
import { listen } from '@tauri-apps/api/event';
|
||||
import { useToast } from '@/hooks/use-toast';
|
||||
|
||||
export type HealthStatus = 'healthy' | 'warning' | 'critical';
|
||||
|
||||
export interface SystemHealth {
|
||||
status: HealthStatus;
|
||||
ram_percent: number;
|
||||
cpu_percent: number;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export function useSystemHealth() {
|
||||
const [health, setHealth] = useState<SystemHealth>({
|
||||
status: 'healthy',
|
||||
ram_percent: 0,
|
||||
cpu_percent: 0,
|
||||
message: 'Sistema saudável',
|
||||
});
|
||||
const [hasShownCriticalToast, setHasShownCriticalToast] = useState(false);
|
||||
const { toast } = useToast();
|
||||
|
||||
useEffect(() => {
|
||||
const unlistenPromise = listen<SystemHealth>('system-state-change', (event) => {
|
||||
const newHealth = event.payload;
|
||||
setHealth(newHealth);
|
||||
|
||||
// Mostrar toast apenas quando entrar em modo Critical (uma vez)
|
||||
if (newHealth.status === 'critical' && !hasShownCriticalToast) {
|
||||
toast({
|
||||
title: 'Modo de Economia Ativado',
|
||||
description: 'Recursos limitados para manter estabilidade. Algumas funcionalidades podem estar temporariamente indisponíveis.',
|
||||
variant: 'destructive',
|
||||
duration: 5000,
|
||||
});
|
||||
setHasShownCriticalToast(true);
|
||||
} else if (newHealth.status !== 'critical') {
|
||||
// Reset flag quando sair do modo crítico
|
||||
setHasShownCriticalToast(false);
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
unlistenPromise.then((unlisten) => unlisten());
|
||||
};
|
||||
}, [hasShownCriticalToast, toast]);
|
||||
|
||||
return health;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user