Public Access
Add the Avalonia app and the xterm renderer, and fix two real bugs
The terminal works end to end. A new integration test drives a real sshd in a container through a real PTY, the real pump, the real loopback WebSocket with its token and origin checks, and a ClientWebSocket standing in for the page: the login banner arrives, typed input round-trips, and `stty size` reports the 100x30 the session asked for. The only untested link left is xterm drawing bytes it was handed. The WebView is de-risked on Windows, which was the plan's largest risk. Not by assertion: with the app running there is an established TCP connection from msedgewebview2 to the data plane port, so WebView2 launched, navigated to the loopback page, executed terminal.js, and completed the WebSocket handshake against the real token and origin checks. Linux remains unproven and the package's own release notes now corroborate the concern -- Linux uses a WPE backend, and it ships a NativeWebDialog described as useful where embedded WebViews may be unavailable. Two bugs found by building it, both of which would have shipped: - ShellStream.Write buffers and needs an explicit Flush. Without one a keystroke is accepted, reported as written, and never reaches the remote: the terminal displays output perfectly and simply stops responding to input. SSH.NET's own WriteLine flushes, which is why the earlier spike never hit it. Found by isolating the pump against real SSH and reading BytesRead=51 -- banner and prompt through, nothing after. - The Windows app manifest needs a supportedOS list, or Avalonia's native control host fails outright and the terminal never starts. Also fixed a genuinely flaky test I happened to catch: SyncCursorTests tampered with the *last* base64url character, whose low bits the decoder ignores when the input length is not a multiple of three -- so a tampered cursor sometimes decoded to identical bytes and verified. It failed roughly one run in thirty, depending on a random key. Now tampers the penultimate character, which is fully significant at every length; 40 consecutive runs are clean. xterm 6.0.0 plus the fit and webgl addons are vendored as UMD bundles rather than built with npm, so a clean clone needs only the .NET SDK. Provenance and licences are recorded next to them, along with the UMD global names terminal.js depends on -- a bundle that switched to ES modules would load without error and leave Terminal undefined. The renderer acknowledges output from term.write's completion callback, not on receipt. Acknowledging early would return flow-control credit for bytes the screen has not caught up with, which is the one thing the credit window exists to measure. TerminalWorkspace moved into DodoSSH.Client.Terminal: it has no Avalonia dependency, and having it there is what let the end-to-end test exist at all. 404 tests pass, zero warnings on a clean rebuild, format clean.
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
using Avalonia;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using DodoSSH.Client.App.Terminal;
|
||||
using DodoSSH.Client.App.ViewModels;
|
||||
using DodoSSH.Client.App.Views;
|
||||
using DodoSSH.Client.Ssh;
|
||||
using DodoSSH.Client.Terminal;
|
||||
|
||||
namespace DodoSSH.Client.App;
|
||||
|
||||
/// <summary>
|
||||
/// The Avalonia application.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Named <c>DodoSshApp</c> rather than the conventional <c>App</c> only because the assembly's root
|
||||
/// namespace already ends in <c>App</c>, and a type whose name matches its namespace forces every
|
||||
/// ambiguous reference to be fully qualified.
|
||||
/// </remarks>
|
||||
internal sealed partial class DodoSshApp : Application
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public override void Initialize() => AvaloniaXamlLoader.Load(this);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnFrameworkInitializationCompleted()
|
||||
{
|
||||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
Compose(desktop);
|
||||
}
|
||||
|
||||
base.OnFrameworkInitializationCompleted();
|
||||
}
|
||||
|
||||
/// <remarks>
|
||||
/// Composed by hand rather than through a container. The graph is four objects deep, and an
|
||||
/// indirection to read through would buy nothing at this size.
|
||||
/// <para>
|
||||
/// The workspace is a local captured by the closures below rather than a field, so this type does
|
||||
/// not own a disposable it has no good place to dispose — an Avalonia <c>Application</c> has no
|
||||
/// disposal hook of its own.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
private static void Compose(IClassicDesktopStyleApplicationLifetime desktop)
|
||||
{
|
||||
var knownHosts = new InMemoryKnownHostStore();
|
||||
|
||||
var workspace = new TerminalWorkspace(
|
||||
new AvaloniaTerminalAssetProvider(),
|
||||
new SshNetConnectionFactory(knownHosts),
|
||||
TimeProvider.System);
|
||||
|
||||
workspace.Start();
|
||||
|
||||
desktop.MainWindow = new MainWindow
|
||||
{
|
||||
DataContext = new MainWindowViewModel(workspace, knownHosts),
|
||||
};
|
||||
|
||||
var shuttingDown = false;
|
||||
|
||||
// Shutdown is deferred rather than blocked on. Sessions hold SSH connections and a listening
|
||||
// socket, and blocking the UI thread on their disposal is how an application comes to take
|
||||
// several seconds to close — or deadlocks, if any of that disposal needs the UI thread.
|
||||
desktop.ShutdownRequested += async (_, e) =>
|
||||
{
|
||||
if (shuttingDown)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
shuttingDown = true;
|
||||
e.Cancel = true;
|
||||
|
||||
await workspace.DisposeAsync().ConfigureAwait(true);
|
||||
|
||||
desktop.Shutdown();
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user