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
|
|
@ -2317,6 +2317,44 @@ export const resetAgent = mutation({
|
|||
},
|
||||
})
|
||||
|
||||
/**
|
||||
* Query para o desktop monitorar o estado da máquina em tempo real.
|
||||
* O desktop faz subscribe nessa query e reage imediatamente quando:
|
||||
* - isActive muda para false (desativação)
|
||||
* - hasValidToken muda para false (reset/revogação de tokens)
|
||||
*/
|
||||
export const getMachineState = query({
|
||||
args: {
|
||||
machineId: v.id("machines"),
|
||||
},
|
||||
handler: async (ctx, { machineId }) => {
|
||||
const machine = await ctx.db.get(machineId)
|
||||
if (!machine) {
|
||||
return { found: false, isActive: false, hasValidToken: false, status: "unknown" as const }
|
||||
}
|
||||
|
||||
// Verifica se existe algum token válido (não revogado e não expirado)
|
||||
const now = Date.now()
|
||||
const tokens = await ctx.db
|
||||
.query("machineTokens")
|
||||
.withIndex("by_machine", (q) => q.eq("machineId", machineId))
|
||||
.take(10)
|
||||
|
||||
const hasValidToken = tokens.some((token) => {
|
||||
if (token.revoked) return false
|
||||
if (token.expiresAt && token.expiresAt < now) return false
|
||||
return true
|
||||
})
|
||||
|
||||
return {
|
||||
found: true,
|
||||
isActive: machine.isActive ?? true,
|
||||
hasValidToken,
|
||||
status: machine.status ?? "unknown",
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
type RemoteAccessEntry = {
|
||||
id: string
|
||||
provider: string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue