feat: add exit confirmation dialog, system tray enhancements, and diagnostic options
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
# ==============================================================================
|
||||
# CyberCore Signer - Diagnóstico e Monitor de Janela Win32 / DWM
|
||||
# Suporta matar instâncias anteriores órfãs e monitorar a janela real.
|
||||
# Uso simples:
|
||||
# powershell -ExecutionPolicy Bypass -File .\scripts\diag-window.ps1
|
||||
# Ou iniciando o app automaticamente junto com o monitor:
|
||||
# powershell -ExecutionPolicy Bypass -File .\scripts\diag-window.ps1 -AutoLaunch
|
||||
# ==============================================================================
|
||||
param (
|
||||
[switch]$AutoLaunch,
|
||||
[string]$ExtraArgs = "--dev"
|
||||
)
|
||||
|
||||
Write-Host "============================================================" -ForegroundColor Cyan
|
||||
Write-Host " CyberCore Signer - Monitor de Janela Win32 / DWM" -ForegroundColor Cyan
|
||||
Write-Host "============================================================" -ForegroundColor Cyan
|
||||
|
||||
# 1. Encerra processos java zumbis anteriores que possam estar travando a porta 21325 ou a bandeja
|
||||
$oldProcs = Get-Process -Name java -ErrorAction SilentlyContinue
|
||||
if ($oldProcs) {
|
||||
Write-Host "[INFO] Encerrando $($oldProcs.Count) processo(s) Java em segundo plano para limpar o ambiente..." -ForegroundColor Yellow
|
||||
$oldProcs | Stop-Process -Force -ErrorAction SilentlyContinue
|
||||
Start-Sleep -Milliseconds 800
|
||||
}
|
||||
|
||||
$signature = @"
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public class Win32WindowWatcher {
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct RECT {
|
||||
public int Left;
|
||||
public int Top;
|
||||
public int Right;
|
||||
public int Bottom;
|
||||
}
|
||||
|
||||
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
|
||||
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool IsWindow(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool IsWindowVisible(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool IsIconic(IntPtr hWnd);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
|
||||
|
||||
[DllImport("user32.dll")]
|
||||
public static extern IntPtr GetForegroundWindow();
|
||||
|
||||
[DllImport("dwmapi.dll")]
|
||||
public static extern int DwmGetWindowAttribute(IntPtr hwnd, int dwAttribute, out int pvAttribute, int cbAttribute);
|
||||
|
||||
public const int DWMWA_CLOAKED = 14;
|
||||
}
|
||||
"@
|
||||
|
||||
Add-Type -TypeDefinition $signature -PassThru | Out-Null
|
||||
|
||||
if ($AutoLaunch) {
|
||||
Write-Host "[LAUNCH] Iniciando cybercore-signer.jar com argumentos: $ExtraArgs" -ForegroundColor Green
|
||||
$jarPath = ".\cybercore-signer.jar"
|
||||
if (-not (Test-Path $jarPath)) {
|
||||
$jarPath = ".\modules\cybercore-app\target\cybercore-signer.jar"
|
||||
}
|
||||
Start-Process -FilePath "java" -ArgumentList "-jar", $jarPath, $ExtraArgs -PassThru | Out-Null
|
||||
}
|
||||
|
||||
Write-Host "Aguardando janela principal abrir (verificando processos e Win32)..." -ForegroundColor Yellow
|
||||
|
||||
$lastState = ""
|
||||
$found = $false
|
||||
$monitoredHwnd = [IntPtr]::Zero
|
||||
|
||||
while ($true) {
|
||||
# Procura via FindWindow pelo título ou pelo MainWindowHandle do processo Java
|
||||
$hWnd = [Win32WindowWatcher]::FindWindow($null, "CyberCore Signer")
|
||||
|
||||
if ($hWnd -eq [IntPtr]::Zero) {
|
||||
$javaProcs = Get-Process -Name java -ErrorAction SilentlyContinue
|
||||
foreach ($p in $javaProcs) {
|
||||
if ($p.MainWindowHandle -ne [IntPtr]::Zero) {
|
||||
$hWnd = $p.MainWindowHandle
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($hWnd -ne [IntPtr]::Zero -and [Win32WindowWatcher]::IsWindow($hWnd)) {
|
||||
if (-not $found -or $hWnd -ne $monitoredHwnd) {
|
||||
$found = $true
|
||||
$monitoredHwnd = $hWnd
|
||||
Write-Host "[OK] JANELA DETECTADA! HWND: $hWnd. Monitorando em tempo real a cada 200ms..." -ForegroundColor Green
|
||||
Write-Host ">>> Passe o mouse sobre a janela agora para observar o que o Windows faz. <<<" -ForegroundColor Magenta
|
||||
}
|
||||
|
||||
$visible = [Win32WindowWatcher]::IsWindowVisible($hWnd)
|
||||
$iconic = [Win32WindowWatcher]::IsIconic($hWnd)
|
||||
$foreground = ([Win32WindowWatcher]::GetForegroundWindow() -eq $hWnd)
|
||||
|
||||
$rect = New-Object Win32WindowWatcher+RECT
|
||||
[Win32WindowWatcher]::GetWindowRect($hWnd, [ref]$rect) | Out-Null
|
||||
$w = $rect.Right - $rect.Left
|
||||
$h = $rect.Bottom - $rect.Top
|
||||
|
||||
$cloakedVal = 0
|
||||
[Win32WindowWatcher]::DwmGetWindowAttribute($hWnd, [Win32WindowWatcher]::DWMWA_CLOAKED, [ref]$cloakedVal, 4) | Out-Null
|
||||
$cloaked = ($cloakedVal -ne 0)
|
||||
|
||||
$currentState = "Visible=$visible | Cloaked(DWM)=$cloaked | Minimized=$iconic | Focused=$foreground | Rect=($($rect.Left),$($rect.Top)) ${w}x${h}"
|
||||
|
||||
if ($currentState -ne $lastState) {
|
||||
$timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss.fff")
|
||||
if (-not $visible -or $cloaked -or $w -le 0 -or $h -le 0) {
|
||||
Write-Host "[$timestamp] [ALERTA-JANELA-SUMIU] $currentState" -ForegroundColor Red
|
||||
} else {
|
||||
Write-Host "[$timestamp] [STATUS] $currentState" -ForegroundColor Gray
|
||||
}
|
||||
$lastState = $currentState
|
||||
}
|
||||
} else {
|
||||
if ($found) {
|
||||
$timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss.fff")
|
||||
Write-Host "[$timestamp] [DESTRUÍDA/FECHADA] O handle da janela não existe mais no Windows!" -ForegroundColor Red
|
||||
$found = $false
|
||||
$lastState = ""
|
||||
$monitoredHwnd = [IntPtr]::Zero
|
||||
}
|
||||
}
|
||||
|
||||
Start-Sleep -Milliseconds 200
|
||||
}
|
||||
Reference in New Issue
Block a user