release.yml (push) Invalid workflow file
Origem: D:/Documents/Github/OllaHub Arquivos omitidos (segredos, bancos de dados, logs, >50 MB): 0
135 lines
4.8 KiB
TypeScript
135 lines
4.8 KiB
TypeScript
'use client';
|
|
|
|
import { TitleBar } from "@/components/titlebar";
|
|
import { Loader2 } from "lucide-react";
|
|
import { useRouter } from "next/navigation";
|
|
import { useEffect, useState, startTransition, useRef } from "react";
|
|
import { useSettingsStore } from "@/store/settings-store";
|
|
import { invoke } from "@tauri-apps/api/core";
|
|
|
|
export default function Home() {
|
|
const router = useRouter();
|
|
const { setSetupCompleted } = useSettingsStore();
|
|
const [isHydrated, setIsHydrated] = useState(false);
|
|
const [isChecking, setIsChecking] = useState(true);
|
|
|
|
// Refs para evitar loops e execuções múltiplas
|
|
const hasCheckedRef = useRef(false);
|
|
const isRedirectingRef = useRef(false);
|
|
|
|
// Hydration check: aguardar Zustand carregar do localStorage
|
|
useEffect(() => {
|
|
setIsHydrated(true);
|
|
}, []);
|
|
|
|
// Guarda de roteamento: verificação de integridade do Ollama + flag persistente
|
|
// Prioridade: Integridade do Sistema > Flag de Setup
|
|
useEffect(() => {
|
|
if (!isHydrated) return;
|
|
if (hasCheckedRef.current) return; // Proteção contra múltiplas execuções
|
|
|
|
const performCheck = async () => {
|
|
if (isRedirectingRef.current) return; // Evitar múltiplos redirecionamentos
|
|
|
|
setIsChecking(true);
|
|
|
|
try {
|
|
// 1. Verificação Real do Sistema (Fonte da Verdade)
|
|
const isOllamaIntact = await invoke<boolean>('verify_ollama_integrity_command');
|
|
|
|
// Ler isSetupCompleted diretamente do store (não usar como dependência)
|
|
const currentSetupStatus = useSettingsStore.getState().isSetupCompleted;
|
|
|
|
if (!isOllamaIntact) {
|
|
// Se o motor não existe, força o setup, não importa o que o storage diga
|
|
console.warn("Integridade do Ollama falhou. Redirecionando para Setup.");
|
|
|
|
if (!isRedirectingRef.current) {
|
|
isRedirectingRef.current = true;
|
|
// Resetar flag de setup se Ollama não está íntegro (ANTES de redirecionar)
|
|
setSetupCompleted(false);
|
|
|
|
// Pequeno delay para garantir que o estado seja persistido no localStorage
|
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
|
|
startTransition(() => {
|
|
router.replace('/setup');
|
|
});
|
|
}
|
|
return;
|
|
}
|
|
|
|
// 2. Verificação de Fluxo de UI (apenas se Ollama está OK)
|
|
if (!isRedirectingRef.current) {
|
|
isRedirectingRef.current = true;
|
|
|
|
if (currentSetupStatus) {
|
|
startTransition(() => {
|
|
router.replace('/chat');
|
|
});
|
|
} else {
|
|
startTransition(() => {
|
|
router.replace('/setup');
|
|
});
|
|
}
|
|
}
|
|
} catch (e) {
|
|
console.error("Falha crítica no check de inicialização", e);
|
|
// Fallback seguro: sempre ir para setup em caso de erro
|
|
if (!isRedirectingRef.current) {
|
|
isRedirectingRef.current = true;
|
|
setSetupCompleted(false);
|
|
|
|
// Pequeno delay para garantir que o estado seja persistido no localStorage
|
|
await new Promise(resolve => setTimeout(resolve, 100));
|
|
|
|
startTransition(() => {
|
|
router.replace('/setup');
|
|
});
|
|
}
|
|
} finally {
|
|
setIsChecking(false);
|
|
hasCheckedRef.current = true; // Marcar como executado
|
|
}
|
|
};
|
|
|
|
performCheck();
|
|
}, [isHydrated, router, setSetupCompleted]);
|
|
|
|
// Enquanto não hidratou ou está verificando, retornar skeleton simples
|
|
if (!isHydrated || isChecking) {
|
|
return (
|
|
<div className="h-screen w-full bg-background overflow-hidden flex flex-col">
|
|
<TitleBar />
|
|
<div className="flex-1 flex items-center justify-center pt-8">
|
|
<div className="flex flex-col items-center gap-4">
|
|
<Loader2 className="h-8 w-8 animate-spin text-primary" />
|
|
<div className="flex flex-col items-center gap-1">
|
|
<span className="text-sm font-medium text-foreground">
|
|
{!isHydrated ? 'Carregando...' : 'Verificando sistema...'}
|
|
</span>
|
|
<span className="text-xs text-muted-foreground">Aguarde um momento...</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
// Após verificação, mostrar loading de redirecionamento (não deve aparecer por muito tempo)
|
|
return (
|
|
<div className="h-screen w-full bg-background overflow-hidden flex flex-col">
|
|
<TitleBar />
|
|
<div className="flex-1 flex items-center justify-center pt-8">
|
|
<div className="flex flex-col items-center gap-4">
|
|
<Loader2 className="h-8 w-8 animate-spin text-primary" />
|
|
<div className="flex flex-col items-center gap-1">
|
|
<span className="text-sm font-medium text-foreground">Redirecionando...</span>
|
|
<span className="text-xs text-muted-foreground">Aguarde um momento...</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|