Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ RDP frame presentation latency (regression fix, 2026-11-23): pure repaint-wave d

## Full Screen Connection Bar

`Views/FullScreenConnectionBar.axaml(.cs)` is the mstsc-style floating bar shown at the top centre of a full screen window. It is hosted by `Views/MainWindow.axaml` (bound to `MainWindowViewModel.IsTerminalFullScreen`, endpoint `SelectedTab.Session.Host`, quality `SelectedTab.Rdp.LinkQualityLevel`, `IsQualityVisible=SelectedTab.IsRdpSession`), `Views/DetachedTabWindow.axaml` (bound to the tab view model), and `Views/RdpMonitorWindow.axaml`. Hosts wire `MinimizeRequested` / `RestoreRequested` / `CloseRequested` / `PinnedChanged` (and workspace/multi-monitor events where applicable).
`Views/FullScreenConnectionBar.axaml(.cs)` is the mstsc-style floating bar shown at the top centre of a full screen window. It is hosted by `Views/MainWindow.axaml` (bound to `MainWindowViewModel.IsTerminalFullScreen`, endpoint `SelectedTab.Session.Host`, quality `SelectedTab.Rdp.LinkQualityLevel`, `IsQualityVisible=SelectedTab.IsRdpSession`), `Views/DetachedTabWindow.axaml` (bound to the tab view model), `Views/RdpWorkspaceWindow.axaml`, and `Views/RdpMonitorWindow.axaml`. Hosts wire `MinimizeRequested` / `RestoreRequested` / `CloseRequested` / `PinnedChanged` (and workspace/multi-monitor events where applicable).

Behaviour that must not regress:

Expand All @@ -92,7 +92,7 @@ Behaviour that must not regress:
- The quality bars are an estimate, not an RDP capability: `RdpViewModel` times a bare TCP connect to the session endpoint every 10 s while connected and maps ≤50 ms/≤100 ms/≤200 ms/longer to 4/3/2/1 bars (`LinkQualityLevel`); 0 means unknown/disconnected. RDP exposes no signal strength, and a full reconnect probe must never be used.
- Minimize from the bar leaves the full screen presentation, so the host must restore it when the window comes back: `MainWindow` uses `_restoreFullScreenAfterMinimize` plus `OnMainWindowPropertyChanged`; `DetachedTabWindow` needs `_restoreFullScreenAfterMinimize` / `_restoreKeepTaskbarAfterMinimize` and the `_suppressPresentationRestore` guard, because leaving the taskbar-visible mode changes `WindowState` and would otherwise look like a user restore. Close maps to `CloseTab(SelectedTab)` in the main window and `Close()` in a detached window - never to shutting down the application.
- **Both full screen modes must hide the drawn chrome, not just the title bar.** `WindowState.FullScreen` only drops the native frame; AtomUI draws its title bar (`IsTitleBarVisible`) inside the client area. `Views/KeepTaskbarFullScreen.cs` owns that: `Enter()` hides the title bar before maximizing, the immersive path calls `HideTitleBar()`.
- **AtomUI 6.3.0's built-in full-screen title bar must stay disabled via `FullScreenTitleBarMode="Hidden"`.** AtomUI 6.3.0 removed `FullscreenHeaderFrame` from `WindowDrawnDecorationsTheme` and introduced `Window.FullScreenTitleBarMode` (default `AutoHide`) inside `WindowChromeLayer`. Every window hosting `FullScreenConnectionBar` (`MainWindow.axaml`, `DetachedTabWindow.axaml`, `RdpMonitorWindow.axaml`) must set `FullScreenTitleBarMode="Hidden"` so AtomUI never activates its built-in full-screen bar or moves `TitleBar` between `NormalSlotTitleBar` and `FullScreenSlotContent`.
- **AtomUI 6.3.0's built-in full-screen title bar must stay disabled via `FullScreenTitleBarMode="Hidden"`.** AtomUI 6.3.0 removed `FullscreenHeaderFrame` from `WindowDrawnDecorationsTheme` and introduced `Window.FullScreenTitleBarMode` (default `AutoHide`) inside `WindowChromeLayer`. Every window hosting `FullScreenConnectionBar` (`MainWindow.axaml`, `DetachedTabWindow.axaml`, `RdpWorkspaceWindow.axaml`, `RdpMonitorWindow.axaml`) must set `FullScreenTitleBarMode="Hidden"` so AtomUI never activates its built-in full-screen bar or moves `TitleBar` between `NormalSlotTitleBar` and `FullScreenSlotContent`.
- **Keep `FullScreenConnectionBar` as a dedicated control rather than replacing it with `Window.FullScreenTitleBar`.** `Window.FullScreenTitleBar` only activates for `WindowState.FullScreen`, whereas CxShell needs the same bar in taskbar-visible maximized mode (`KeepTaskbarFullScreen`) and `RdpMonitorWindow` borderless mode, with the centred 8 px / 500 ms mstsc hot-zone, RDP link quality, pin persistence, multi-monitor popup lock, workspace tab switching, and drag-restore.
- `KeepTaskbarFullScreen` owns `HideTitleBar`/`RestoreTitleBar` and `HideDecorations`/`RestoreDecorations` (`Window.WindowDecorations = None`, previous values saved once). Both helpers are idempotent so switching between "keep taskbar" and immersive full screen never loses the original state. Restore them on every exit path (after leaving full screen, never before), including an external takeover (window manager shortcut, native caption button): `MainWindow.OnMainWindowPropertyChanged` and `DetachedTabWindow.OnWindowPropertyChanged` restore the chrome whenever the window ends up outside full screen without `_keepTaskbarFullScreen.IsActive`. Never bind `IsTitleBarVisible` or `WindowDecorations` from XAML.

Expand Down
57 changes: 45 additions & 12 deletions Controls/DataGridSourceAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System.Collections;
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using AtomUI.Desktop.Controls;
using Avalonia.Data;
using CxShell.Models;

namespace CxShell.Controls;

Expand All @@ -12,11 +14,15 @@ namespace CxShell.Controls;
/// keeps the source's row keys mapped to the application's item instances.
/// This is deliberately a data-source helper, not a replacement DataGrid.
/// </summary>
public sealed class DataGridSourceAdapter<T> : IDisposable
public sealed class DataGridSourceAdapter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] T> : IDisposable
{
private static readonly string[] NestedKeyPropertyNames = ["Session", "Entry", "Recording"];
private static readonly string[] DirectKeyPropertyNames = ["Id", "Key", "FullPath", "Path", "Name"];
private static readonly IComparer<object?> ObjectComparer = Comparer<object?>.Create(CompareValues);
private readonly IReadOnlyList<T> _items;
private readonly Dictionary<DataGridRowKey, T> _itemsByKey = new();
private readonly (string Name, PropertyInfo Property)? _nestedKeyProperty;
private readonly (string Name, PropertyInfo Property)[] _directKeyProperties;
private readonly DataGridLocalSource<T> _source;
private bool _disposed;

Expand All @@ -26,14 +32,34 @@ public DataGridSourceAdapter(IReadOnlyList<T> items, bool snapshot = false)
_items = snapshot ? items.ToArray() : items;

var descriptor = DataGridLocalSourceDescriptor.For<T>(GetRowKey);
var propertiesByName = new Dictionary<string, PropertyInfo>(StringComparer.Ordinal);
foreach (var property in typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance))
{
if (property.GetMethod == null || property.GetIndexParameters().Length != 0)
continue;

propertiesByName.TryAdd(property.Name, property);
AddReflectedField(descriptor, property);
}

foreach (var nestedName in NestedKeyPropertyNames)
{
if (propertiesByName.TryGetValue(nestedName, out var nestedProp))
{
_nestedKeyProperty = (nestedName, nestedProp);
break;
}
}

var directProps = new List<(string Name, PropertyInfo Property)>(DirectKeyPropertyNames.Length);
foreach (var keyName in DirectKeyPropertyNames)
{
if (propertiesByName.TryGetValue(keyName, out var directProp))
directProps.Add((keyName, directProp));
}

_directKeyProperties = directProps.ToArray();

_source = DataGridLocalSource<T>.Create(
_items,
descriptor,
Expand Down Expand Up @@ -257,28 +283,35 @@ private static bool SupportsScalar(Type type)
_ => null
};

private static string GetStableKeyText(T item)
private string GetStableKeyText(T item)
{
if (item == null)
return "null";

var type = item.GetType();
foreach (var nestedPropertyName in new[] { "Session", "Entry", "Recording" })
var typeName = item.GetType().FullName;
if (_nestedKeyProperty is { } nestedProp)
{
var nested = type.GetProperty(nestedPropertyName, BindingFlags.Public | BindingFlags.Instance)?.GetValue(item);
var nestedId = nested?.GetType().GetProperty("Id", BindingFlags.Public | BindingFlags.Instance)?.GetValue(nested);
var nested = nestedProp.Property.GetValue(item);
var nestedId = TryGetNestedId(nested);
if (nestedId != null)
return $"{type.FullName}:{nestedPropertyName}:{nestedId}:{RuntimeHelpers.GetHashCode(item)}";
return $"{typeName}:{nestedProp.Name}:{nestedId}:{RuntimeHelpers.GetHashCode(item)}";
}

foreach (var propertyName in new[] { "Id", "Key", "FullPath", "Path", "Name" })
foreach (var (propertyName, property) in _directKeyProperties)
{
var property = type.GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance);
var value = property?.GetValue(item);
var value = property.GetValue(item);
if (value != null && !string.IsNullOrWhiteSpace(value.ToString()))
return $"{type.FullName}:{propertyName}:{value}:{RuntimeHelpers.GetHashCode(item)}";
return $"{typeName}:{propertyName}:{value}:{RuntimeHelpers.GetHashCode(item)}";
}

return $"{type.FullName}:{RuntimeHelpers.GetHashCode(item)}";
return $"{typeName}:{RuntimeHelpers.GetHashCode(item)}";
}

private static object? TryGetNestedId(object? nested) => nested switch
{
SessionInfo session => session.Id,
ConnectionAuditEntry entry => entry.Id,
SessionRecording recording => recording.Id,
_ => null
};
}
24 changes: 24 additions & 0 deletions CxShell.Tests/AgentRuntimeTestJsonInitializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Runtime.CompilerServices;
using System.Text.Json;
using System.Text.Json.Serialization.Metadata;
using CxShell.Services;

namespace CxShell.Tests;

internal static class AgentRuntimeTestJsonInitializer
{
private static readonly JsonSerializerOptions CamelCaseTestOptions = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
TypeInfoResolver = JsonTypeInfoResolver.Combine(
AppCamelCaseJsonContext.Default,
new DefaultJsonTypeInfoResolver())
};

[ModuleInitializer]
internal static void Initialize()
{
AppJsonOptions.TestCamelCaseTypeInfoFallback =
static type => CamelCaseTestOptions.GetTypeInfo(type);
}
}
1 change: 1 addition & 0 deletions CxShell.Tests/CxShell.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
Expand Down
48 changes: 48 additions & 0 deletions CxShell.Tests/SshNetX11ApiSurfaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,52 @@ public void X11RequestIsNotExposedThroughSupportedSshClientApi()
Assert.True(requestMethod!.IsPublic);
Assert.False(publicClientHasX11EntryPoint);
}

[Fact]
public void ShellStreamAndDescriptorTargetsExistForAotAndAgentForwarding()
{
MethodInfo? changeWindowSize = typeof(ShellStream).GetMethod(
nameof(ShellStream.ChangeWindowSize),
BindingFlags.Public | BindingFlags.Instance,
binder: null,
types: [typeof(uint), typeof(uint), typeof(uint), typeof(uint)],
modifiers: null);
Assert.NotNull(changeWindowSize);
Assert.True(changeWindowSize!.IsPublic);

FieldInfo? channelField = typeof(ShellStream).GetField(
"_channel",
BindingFlags.Instance | BindingFlags.NonPublic);
Assert.NotNull(channelField);

Assembly sshNetAssembly = typeof(SshClient).Assembly;
Type? channelType = sshNetAssembly.GetType("Renci.SshNet.Channels.Channel");
Assert.NotNull(channelType);
Assert.NotNull(channelType!.GetField("_session", BindingFlags.Instance | BindingFlags.NonPublic));
Assert.NotNull(channelType.GetProperty("RemoteChannelNumber", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic));

Type? sessionType = sshNetAssembly.GetType("Renci.SshNet.Session");
Assert.NotNull(sessionType);
foreach (string eventName in new[]
{
"ChannelOpenReceived",
"ChannelDataReceived",
"ChannelEofReceived",
"ChannelCloseReceived"
})
{
Assert.NotNull(sessionType!.GetEvent(eventName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic));
}

MethodInfo? sendMessage = sessionType!
.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
.FirstOrDefault(method =>
method.Name.EndsWith("SendMessage", StringComparison.Ordinal) &&
method.GetParameters() is [{ ParameterType.Name: "Message" }]);
Assert.NotNull(sendMessage);

Type? messageEventArgsType = sshNetAssembly.GetType("Renci.SshNet.MessageEventArgs`1");
Assert.NotNull(messageEventArgsType);
Assert.NotNull(messageEventArgsType!.GetProperty("Message", BindingFlags.Instance | BindingFlags.Public));
}
}
Loading
Loading