Fix: Remote Desktop — 60fps, Screen-Wechsel live, Consent-Dialog sichtbar (v2.3.0)

- CaptureModeRunner: Thread.Sleep(150) → 16ms (~60fps) + Skip-if-unchanged via Pixel-Hash
- RtcService: rdp_switch_screen Handler — Screen wechseln ohne Consent-Dialog
- RtcService: Fallback bei Consent-Fehler → rdp_denied statt silent capture
- RdpConsentWindow: WindowStyle=ToolWindow + ShowInTaskbar=True (jetzt in Taskleiste sichtbar)
- RemoteDesktopPanel: Screen-Dropdown auch während aktiver Verbindung nutzbar
- Version: 2.2.0 → 2.3.0

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-17 09:23:36 +02:00
parent 0b2943087d
commit 99830e25f4
9 changed files with 64 additions and 16 deletions

View File

@@ -6,7 +6,7 @@ namespace ITNexusAgent;
public class AgentWorker
{
private const string Version = "2.2.0";
private const string Version = "2.3.0";
private const string DataDir = @"C:\ProgramData\IT Nexus Agent";
private const string ConfigPath = @"C:\ProgramData\IT Nexus Agent\config.json";
private const string StatusPath = @"C:\ProgramData\IT Nexus Agent\status.json";

View File

@@ -24,7 +24,6 @@ public static class CaptureModeRunner
var encParams = new EncoderParameters(1);
encParams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 60L);
// Capture-Region bestimmen: 0 = alle Screens, 1-N = spezifischer Screen
var allScreens = System.Windows.Forms.Screen.AllScreens;
Rectangle captureRect;
if (screenIdx <= 0 || screenIdx > allScreens.Length)
@@ -40,14 +39,27 @@ public static class CaptureModeRunner
captureRect = allScreens[screenIdx - 1].Bounds;
}
uint lastHash = 0;
var sw = System.Diagnostics.Stopwatch.StartNew();
while (tcp.Connected)
{
sw.Restart();
try
{
using var bmp = new Bitmap(captureRect.Width, captureRect.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
using (var g = Graphics.FromImage(bmp))
g.CopyFromScreen(captureRect.X, captureRect.Y, 0, 0, new Size(captureRect.Width, captureRect.Height));
var hash = SampleHash(bmp);
if (hash == lastHash)
{
var elapsed = (int)sw.ElapsedMilliseconds;
if (elapsed < 16) Thread.Sleep(16 - elapsed);
continue;
}
lastHash = hash;
byte[] jpeg;
using (var ms = new MemoryStream())
{
@@ -55,16 +67,32 @@ public static class CaptureModeRunner
jpeg = ms.ToArray();
}
// 4-Byte Länge (LE) + JPEG-Daten
stream.Write(BitConverter.GetBytes(jpeg.Length));
stream.Write(jpeg);
stream.Flush();
}
catch { break; }
Thread.Sleep(150); // ~6-7 fps
var frameMs = (int)sw.ElapsedMilliseconds;
if (frameMs < 16) Thread.Sleep(16 - frameMs); // cap at ~60 fps
}
}
catch { /* Verbindung fehlgeschlagen → Exit */ }
}
private static uint SampleHash(Bitmap bmp)
{
// Sample 64 evenly-distributed pixels — fast change detection, O(1)
uint h = 2166136261u;
int w = bmp.Width, ht = bmp.Height;
int stepX = Math.Max(1, w / 8);
int stepY = Math.Max(1, ht / 8);
for (int y = 0; y < ht; y += stepY)
for (int x = 0; x < w; x += stepX)
{
var c = bmp.GetPixel(x, y);
h = (h ^ (uint)c.ToArgb()) * 16777619u;
}
return h;
}
}

View File

@@ -7,8 +7,8 @@
<UseWindowsForms>true</UseWindowsForms>
<AssemblyName>IT-Nexus-Agent</AssemblyName>
<RootNamespace>ITNexusAgent</RootNamespace>
<Version>2.0.0</Version>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<Version>2.3.0</Version>
<AssemblyVersion>2.3.0.0</AssemblyVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>

View File

@@ -70,6 +70,15 @@ public class RtcService
_ = ConsentAndCaptureAsync(ws, screenIdx, captureCts.Token);
AgentWorker.Log($"RDP: Consent angefordert (screen={screenIdx})");
}
else if (type == "rdp_switch_screen" && captureCts != null)
{
// Consent bereits erteilt — nur Screen wechseln, kein erneuter Dialog
var newScreen = obj["screen"]?.ToObject<int>() ?? 0;
captureCts.Cancel();
captureCts = CancellationTokenSource.CreateLinkedTokenSource(ct);
_ = CapturePipeLoopAsync(ws, newScreen, captureCts.Token);
AgentWorker.Log($"RDP: Screen gewechselt zu {newScreen}");
}
else if (type == "rdp_stop" && captureCts != null)
{
captureCts.Cancel();
@@ -93,8 +102,10 @@ public class RtcService
if (!SpawnConsentHelper(exePath, consentPort.ToString()))
{
consentListener.Stop();
AgentWorker.Log("RDP: Consent-Helper fehlgeschlagen, starte ohne Consent");
await CapturePipeLoopAsync(ws, screenIdx, ct);
AgentWorker.Log("RDP: Consent-Helper fehlgeschlagen, verweigere Zugriff");
var failed = Encoding.UTF8.GetBytes("{\"type\":\"rdp_denied\",\"reason\":\"consent_spawn_failed\"}");
if (ws.State == WebSocketState.Open)
await ws.SendAsync(new ArraySegment<byte>(failed), WebSocketMessageType.Text, true, CancellationToken.None);
return;
}

View File

@@ -40,7 +40,7 @@ public class ShellService
+ $"/ws?type=agent&key={Uri.EscapeDataString(_agentKey)}&hostname={Uri.EscapeDataString(_hostname)}";
using var ws = new ClientWebSocket();
ws.Options.SetRequestHeader("User-Agent", "IT-Nexus-Agent/2.1.2");
ws.Options.SetRequestHeader("User-Agent", "IT-Nexus-Agent/2.3.0");
await ws.ConnectAsync(new Uri(wsUrl), ct);
AgentWorker.Log("SHELL: WebSocket verbunden");

View File

@@ -1,15 +1,16 @@
<Window x:Class="ITNexusAgent.UI.RdpConsentWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="IT Nexus Bildschirmzugriff"
Title="IT Nexus Bildschirmzugriff angefordert"
Width="480" Height="Auto"
SizeToContent="Height"
WindowStartupLocation="CenterScreen"
ResizeMode="NoResize"
WindowStyle="None"
WindowStyle="ToolWindow"
AllowsTransparency="False"
Background="#1A1D2E"
Topmost="True"
ShowInTaskbar="True"
FontFamily="Segoe UI">
<Window.Resources>

View File

@@ -1,5 +1,5 @@
#define MyAppName "IT Nexus Agent"
#define MyAppVersion "2.2.0"
#define MyAppVersion "2.3.0"
#define MyAppPublisher "Cereda Systems GmbH"
#define MyAppURL "https://it-nexus.cereda-systems.de"
#define MyAppExeName "IT-Nexus-Agent.exe"