feat: Implementação completa do NoIdle - Cliente, Backend e Scripts
- Cliente Windows com modo silencioso e auto-start robusto - Backend Node.js + API REST - Frontend Next.js + Dashboard - Scripts PowerShell de configuração e diagnóstico - Documentação completa - Build scripts para Windows e Linux - Solução de auto-start após reinicialização Resolução do problema: Cliente não voltava ativo após reboot Solução: Registro do Windows + Task Scheduler + Modo silencioso
This commit is contained in:
212
CONFIGURAR_AUTOSTART_NOIDLE.ps1
Normal file
212
CONFIGURAR_AUTOSTART_NOIDLE.ps1
Normal file
@@ -0,0 +1,212 @@
|
||||
# Script para Configurar/Reparar Inicialização Automática do NoIdle
|
||||
# Execute este script no Windows para garantir que o NoIdle inicie automaticamente
|
||||
# Uso: .\CONFIGURAR_AUTOSTART_NOIDLE.ps1
|
||||
|
||||
param(
|
||||
[switch]$Remove,
|
||||
[switch]$Force
|
||||
)
|
||||
|
||||
$AppName = "NoIdle"
|
||||
$TaskName = "NoIdle_Monitor"
|
||||
$InstallDir = "$env:ProgramFiles\$AppName"
|
||||
$ExePath = "$InstallDir\NoIdle.exe"
|
||||
$RegKey = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Run"
|
||||
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host "NoIdle - Configurador de Auto-Start" -ForegroundColor Cyan
|
||||
Write-Host "========================================" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Função para verificar se está rodando como Admin (não necessário, mas recomendado)
|
||||
function Test-Administrator {
|
||||
$currentUser = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
|
||||
return $currentUser.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
|
||||
}
|
||||
|
||||
# Se o usuário quer remover auto-start
|
||||
if ($Remove) {
|
||||
Write-Host "Removendo configurações de auto-start..." -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
|
||||
# Remover do Registry
|
||||
Write-Host "[1/2] Removendo entrada do Registro..." -ForegroundColor Cyan
|
||||
try {
|
||||
Remove-ItemProperty -Path $RegKey -Name $AppName -ErrorAction SilentlyContinue
|
||||
Write-Host " ✅ Entrada do registro removida" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host " ⚠️ Entrada do registro não encontrada" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
# Remover Task Scheduler
|
||||
Write-Host "[2/2] Removendo tarefa agendada..." -ForegroundColor Cyan
|
||||
try {
|
||||
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue
|
||||
Write-Host " ✅ Tarefa agendada removida" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host " ⚠️ Tarefa agendada não encontrada" -ForegroundColor Yellow
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "✅ Auto-start removido com sucesso!" -ForegroundColor Green
|
||||
exit 0
|
||||
}
|
||||
|
||||
# MODO: CONFIGURAR/REPARAR AUTO-START
|
||||
|
||||
Write-Host "Verificando instalação..." -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Verificar se o executável existe
|
||||
if (-not (Test-Path $ExePath)) {
|
||||
Write-Host "❌ ERRO: NoIdle não está instalado!" -ForegroundColor Red
|
||||
Write-Host " Caminho esperado: $ExePath" -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
Write-Host "Por favor, instale o NoIdle primeiro." -ForegroundColor Yellow
|
||||
exit 1
|
||||
}
|
||||
|
||||
Write-Host "✅ NoIdle encontrado em: $ExePath" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
||||
# Verificar se já está configurado
|
||||
$alreadyConfigured = $false
|
||||
$registryConfigured = $false
|
||||
$taskConfigured = $false
|
||||
|
||||
Write-Host "Verificando configuração atual..." -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# Verificar Registry
|
||||
try {
|
||||
$regValue = Get-ItemProperty -Path $RegKey -Name $AppName -ErrorAction SilentlyContinue
|
||||
if ($regValue) {
|
||||
$registryConfigured = $true
|
||||
Write-Host "✅ Registro do Windows: Configurado" -ForegroundColor Green
|
||||
Write-Host " Valor: $($regValue.$AppName)" -ForegroundColor Gray
|
||||
} else {
|
||||
Write-Host "❌ Registro do Windows: NÃO configurado" -ForegroundColor Red
|
||||
}
|
||||
} catch {
|
||||
Write-Host "❌ Registro do Windows: NÃO configurado" -ForegroundColor Red
|
||||
}
|
||||
|
||||
# Verificar Task Scheduler
|
||||
try {
|
||||
$task = Get-ScheduledTask -TaskName $TaskName -ErrorAction SilentlyContinue
|
||||
if ($task) {
|
||||
$taskConfigured = $true
|
||||
$taskState = $task.State
|
||||
Write-Host "✅ Task Scheduler: Configurado (Estado: $taskState)" -ForegroundColor Green
|
||||
} else {
|
||||
Write-Host "❌ Task Scheduler: NÃO configurado" -ForegroundColor Red
|
||||
}
|
||||
} catch {
|
||||
Write-Host "❌ Task Scheduler: NÃO configurado" -ForegroundColor Red
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
|
||||
# Se já está configurado e não foi forçado, perguntar se quer reconfigurar
|
||||
if ($registryConfigured -and $taskConfigured -and -not $Force) {
|
||||
Write-Host "✅ Auto-start já está configurado!" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
$resposta = Read-Host "Deseja reconfigurar mesmo assim? (S/N)"
|
||||
if ($resposta -ne "S" -and $resposta -ne "s") {
|
||||
Write-Host "Operação cancelada." -ForegroundColor Yellow
|
||||
exit 0
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Configurando auto-start..." -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
|
||||
# 1. Configurar Registry
|
||||
Write-Host "[1/2] Configurando Registro do Windows..." -ForegroundColor Cyan
|
||||
try {
|
||||
$registryValue = "`"$ExePath`" --silent"
|
||||
Set-ItemProperty -Path $RegKey -Name $AppName -Value $registryValue -Type String -Force
|
||||
Write-Host " ✅ Registro configurado com sucesso" -ForegroundColor Green
|
||||
Write-Host " Comando: $registryValue" -ForegroundColor Gray
|
||||
} catch {
|
||||
Write-Host " ❌ Erro ao configurar registro: $_" -ForegroundColor Red
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
|
||||
# 2. Configurar Task Scheduler
|
||||
Write-Host "[2/2] Configurando Task Scheduler..." -ForegroundColor Cyan
|
||||
try {
|
||||
# Remover tarefa existente se houver
|
||||
Unregister-ScheduledTask -TaskName $TaskName -Confirm:$false -ErrorAction SilentlyContinue | Out-Null
|
||||
|
||||
# Criar nova tarefa
|
||||
$action = New-ScheduledTaskAction -Execute "`"$ExePath`"" -Argument '--silent'
|
||||
$trigger = New-ScheduledTaskTrigger -AtLogOn -User $env:USERNAME
|
||||
$principal = New-ScheduledTaskPrincipal -UserId $env:USERNAME -LogonType Interactive -RunLevel Limited
|
||||
$settings = New-ScheduledTaskSettingsSet `
|
||||
-AllowStartIfOnBatteries `
|
||||
-DontStopIfGoingOnBatteries `
|
||||
-StartWhenAvailable `
|
||||
-RestartCount 3 `
|
||||
-RestartInterval (New-TimeSpan -Minutes 1) `
|
||||
-ExecutionTimeLimit (New-TimeSpan -Days 0)
|
||||
|
||||
Register-ScheduledTask `
|
||||
-TaskName $TaskName `
|
||||
-Action $action `
|
||||
-Trigger $trigger `
|
||||
-Principal $principal `
|
||||
-Settings $settings `
|
||||
-Description "Monitora atividades do usuário para o sistema NoIdle" `
|
||||
-Force | Out-Null
|
||||
|
||||
Write-Host " ✅ Task Scheduler configurado com sucesso" -ForegroundColor Green
|
||||
Write-Host " Nome da tarefa: $TaskName" -ForegroundColor Gray
|
||||
} catch {
|
||||
Write-Host " ⚠️ Erro ao configurar Task Scheduler: $_" -ForegroundColor Yellow
|
||||
Write-Host " (O Registry ainda funcionará)" -ForegroundColor Gray
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Write-Host "✅ Configuração concluída!" -ForegroundColor Green
|
||||
Write-Host "========================================" -ForegroundColor Green
|
||||
Write-Host ""
|
||||
|
||||
# Verificar se o processo já está rodando
|
||||
$runningProcess = Get-Process -Name "NoIdle" -ErrorAction SilentlyContinue
|
||||
if ($runningProcess) {
|
||||
Write-Host "⚠️ O NoIdle já está em execução (PID: $($runningProcess.Id))" -ForegroundColor Yellow
|
||||
Write-Host ""
|
||||
$reiniciar = Read-Host "Deseja reiniciar o NoIdle para aplicar as mudanças? (S/N)"
|
||||
if ($reiniciar -eq "S" -or $reiniciar -eq "s") {
|
||||
Write-Host "Parando processo atual..." -ForegroundColor Cyan
|
||||
Stop-Process -Name "NoIdle" -Force
|
||||
Start-Sleep -Seconds 2
|
||||
Write-Host "Iniciando NoIdle..." -ForegroundColor Cyan
|
||||
Start-Process -FilePath $ExePath -ArgumentList "--silent" -WindowStyle Hidden
|
||||
Write-Host "✅ NoIdle reiniciado!" -ForegroundColor Green
|
||||
}
|
||||
} else {
|
||||
Write-Host "NoIdle não está em execução." -ForegroundColor Yellow
|
||||
$iniciar = Read-Host "Deseja iniciar o NoIdle agora? (S/N)"
|
||||
if ($iniciar -eq "S" -or $iniciar -eq "s") {
|
||||
Write-Host "Iniciando NoIdle..." -ForegroundColor Cyan
|
||||
Start-Process -FilePath $ExePath -ArgumentList "--silent" -WindowStyle Hidden
|
||||
Write-Host "✅ NoIdle iniciado!" -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "📋 Resumo:" -ForegroundColor Cyan
|
||||
Write-Host " - Método 1: Registro do Windows (iniciar ao fazer login)" -ForegroundColor White
|
||||
Write-Host " - Método 2: Task Scheduler (mais confiável, com restart automático)" -ForegroundColor White
|
||||
Write-Host ""
|
||||
Write-Host "O NoIdle agora iniciará automaticamente quando você fizer login no Windows." -ForegroundColor Green
|
||||
Write-Host ""
|
||||
Write-Host "Para remover o auto-start, execute:" -ForegroundColor Yellow
|
||||
Write-Host " .\CONFIGURAR_AUTOSTART_NOIDLE.ps1 -Remove" -ForegroundColor Gray
|
||||
Write-Host ""
|
||||
|
||||
Reference in New Issue
Block a user