feat(devices): adiciona modais de confirmacao e deteccao em tempo real
All checks were successful
All checks were successful
- Adiciona modais de confirmacao para resetar e desativar dispositivos - Cria query getMachineState no Convex para monitoramento em tempo real - Implementa MachineStateMonitor no desktop para detectar mudancas - Desktop redireciona para tela de registro apos reset - Desktop mostra tela de desativacao imediatamente apos bloqueio 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
cd3305f1e3
commit
0bfe4edc6c
4 changed files with 263 additions and 2 deletions
|
|
@ -6,12 +6,19 @@ import { listen } from "@tauri-apps/api/event"
|
|||
import { Store } from "@tauri-apps/plugin-store"
|
||||
import { appLocalDataDir, join } from "@tauri-apps/api/path"
|
||||
import { ExternalLink, Eye, EyeOff, Loader2, RefreshCw } from "lucide-react"
|
||||
import { ConvexReactClient } from "convex/react"
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "./components/ui/tabs"
|
||||
import { cn } from "./lib/utils"
|
||||
import { ChatApp } from "./chat"
|
||||
import { DeactivationScreen } from "./components/DeactivationScreen"
|
||||
import { MachineStateMonitor } from "./components/MachineStateMonitor"
|
||||
import type { SessionStartedEvent, UnreadUpdateEvent, NewMessageEvent, SessionEndedEvent } from "./chat/types"
|
||||
|
||||
// URL do Convex para subscription em tempo real
|
||||
const CONVEX_URL = import.meta.env.MODE === "production"
|
||||
? "https://convex.esdrasrenan.com.br"
|
||||
: (import.meta.env.VITE_CONVEX_URL ?? "https://convex.esdrasrenan.com.br")
|
||||
|
||||
type MachineOs = {
|
||||
name: string
|
||||
version?: string | null
|
||||
|
|
@ -321,6 +328,9 @@ function App() {
|
|||
const selfHealPromiseRef = useRef<Promise<boolean> | null>(null)
|
||||
const lastHealAtRef = useRef(0)
|
||||
|
||||
// Cliente Convex para monitoramento em tempo real do estado da maquina
|
||||
const [convexClient, setConvexClient] = useState<ConvexReactClient | null>(null)
|
||||
|
||||
const [provisioningCode, setProvisioningCode] = useState("")
|
||||
const [validatedCompany, setValidatedCompany] = useState<{ id: string; name: string; slug: string; tenantId: string } | null>(null)
|
||||
const [companyName, setCompanyName] = useState("")
|
||||
|
|
@ -693,6 +703,56 @@ useEffect(() => {
|
|||
rustdeskInfoRef.current = rustdeskInfo
|
||||
}, [rustdeskInfo])
|
||||
|
||||
// Cria/destrói cliente Convex quando o token muda
|
||||
useEffect(() => {
|
||||
if (!token) {
|
||||
if (convexClient) {
|
||||
convexClient.close()
|
||||
setConvexClient(null)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Cria novo cliente Convex para monitoramento em tempo real
|
||||
const client = new ConvexReactClient(CONVEX_URL, {
|
||||
unsavedChangesWarning: false,
|
||||
})
|
||||
setConvexClient(client)
|
||||
|
||||
return () => {
|
||||
client.close()
|
||||
}
|
||||
}, [token]) // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
// Callbacks para quando a máquina for desativada ou resetada
|
||||
const handleMachineDeactivated = useCallback(() => {
|
||||
console.log("[App] Máquina foi desativada - mostrando tela de bloqueio")
|
||||
setIsMachineActive(false)
|
||||
}, [])
|
||||
|
||||
const handleTokenRevoked = useCallback(async () => {
|
||||
console.log("[App] Token foi revogado - voltando para tela de registro")
|
||||
if (store) {
|
||||
try {
|
||||
await store.delete("token")
|
||||
await store.delete("config")
|
||||
await store.save()
|
||||
} catch (err) {
|
||||
console.error("Falha ao limpar store", err)
|
||||
}
|
||||
}
|
||||
tokenVerifiedRef.current = false
|
||||
autoLaunchRef.current = false
|
||||
setToken(null)
|
||||
setConfig(null)
|
||||
setStatus(null)
|
||||
setIsMachineActive(true)
|
||||
setError("Este dispositivo foi resetado. Informe o código de provisionamento para reconectar.")
|
||||
try {
|
||||
const p = await invoke<MachineProfile>("collect_machine_profile")
|
||||
setProfile(p)
|
||||
} catch {}
|
||||
}, [store])
|
||||
|
||||
useEffect(() => {
|
||||
if (!store || !config) return
|
||||
|
|
@ -1514,6 +1574,15 @@ const resolvedAppUrl = useMemo(() => {
|
|||
|
||||
return (
|
||||
<div className="min-h-screen grid place-items-center bg-slate-50 p-6">
|
||||
{/* Monitor de estado da maquina em tempo real via Convex */}
|
||||
{token && config?.machineId && convexClient && (
|
||||
<MachineStateMonitor
|
||||
client={convexClient}
|
||||
machineId={config.machineId}
|
||||
onDeactivated={handleMachineDeactivated}
|
||||
onTokenRevoked={handleTokenRevoked}
|
||||
/>
|
||||
)}
|
||||
{token && !isMachineActive ? (
|
||||
<DeactivationScreen companyName={companyName} />
|
||||
) : (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue