Stop the terminal's WebView painting over the setup screens

The shell layered its setup and unlock screens over the terminal, which does
not work: NativeWebView attaches a real Win32 child HWND through
NativeControlHost, and a child window composites above everything its parent
paints regardless of visual-tree z-order. The cards rendered sliced at the
terminal column's left edge; at the window's default width every one of their
buttons fell inside the WebView's rectangle, so the flow could only be
completed by keyboard, and a click in that region handed Win32 focus to
WebView2 so the text boxes silently stopped accepting keystrokes.

The WebView is now collapsed while the vault is not unlocked. The comment
that previously forbade this — hiding it means never realising it — was
wrong: NativeControlHost creates the native attachment on attach to the
visual tree, never consulting layout or visibility, and NativeWebView replays
a Source assigned before its adapter exists. A collapsed WebView still starts
WebView2, loads the page and lets the renderer attach. Confirmed: 35
msedgewebview2 processes with the control collapsed. What the first
connection after unlocking actually depends on is the existing await on
WaitForRendererAsync, since the data plane drops frames when no renderer is
attached.

Also fixes the second visible defect: the default server URL was
https://localhost:7217, the API's *second* launch profile, while the README,
its appsettings and a plain `dotnet run` all use http://localhost:5233 — so
nothing was listening, and an HTTPS client against a plaintext port reports
"The SSL connection could not be established", which reads as a certificate
problem. The default now matches, a missing scheme is rejected by name
instead of parsing as scheme "localhost", and that specific TLS failure now
suggests http://. Both new tests fail when the fixes are reverted.

Corrections to claims I made earlier and should not have:

- docs/platform-flags.md asserted the opposite of the mechanism above and
  cited an established msedgewebview2 connection as verification. That
  observation was taken while the overlay was showing but, because of this
  very bug, the WebView was uncovered and in plain view — so it confirmed
  only that a visible WebView is realised. A process-level check cannot
  verify a rendering claim. The entry was also filed under "Local cache".
- ITerminalHost was documented as the live seam the app plugs into, with a
  stub standing in for headless tests. It has no implementation anywhere and
  no test uses it; the view navigates the control directly. It also counted
  Avalonia.Controls.WebView and NativeWebView as two interchangeable
  backends when they are one component, with the Linux backend backwards.
- The README claimed the shell's whole path was covered by tests. Its state
  machine is; its layout is covered by nothing, and a headless test could
  not have caught this — headless has no native window, so it would have
  rendered correctly and confirmed the wrong belief.

Verified by screenshotting the running app: the card renders complete and
centred at the default size, with the button clickable.
This commit is contained in:
2026-07-29 13:26:30 +02:00
parent b9e7c258ae
commit 0500e43e02
7 changed files with 206 additions and 35 deletions
+23 -5
View File
@@ -31,9 +31,21 @@
</Window.Styles>
<!--
The terminal's WebView stays in the visual tree at all times and is covered by the setup and unlock
screens rather than being collapsed. A NativeWebView hosts a real child window, and hiding it means
never realising it — which would leave the terminal blank on the first connection after unlocking.
The terminal's WebView is collapsed whenever the vault is not unlocked, and that is not a style
choice. NativeWebView hosts a real Win32 child window through NativeControlHost, and a child window
composites above everything the parent paints — so no sibling in this visual tree can cover it,
whatever the z-order says. Layering the setup screens over it left them sliced at the WebView's left
edge, with their buttons unreachable at the window's default width.
Collapsing is safe, which the earlier version of this comment denied: NativeControlHost creates the
native control when the control is attached to the visual tree, not when it is laid out or shown, and
an assigned Source is replayed once the adapter exists. IsVisible=false therefore still starts
WebView2, still loads the page and still lets the renderer attach its socket; it only swaps
ShowInBounds for HideWithSize. Flipping it back re-pushes the bounds.
What the first connection after unlocking actually depends on is the await in
VaultViewModel.ConnectAsync — the data plane drops frames when no renderer is attached, so the gate
is that await, never this control's visibility.
-->
<Panel>
@@ -205,14 +217,20 @@
<!--
One WebView hosting every terminal. Not one per tab: each WebView2 is a separate browser process
tree, so twenty tabs would cost twenty of them.
IsVisible is load-bearing rather than cosmetic — see the note on the root Panel. Without it the
native child window paints over the setup and unlock screens and swallows their input.
-->
<NativeWebView Grid.Row="2" x:Name="Terminal" />
<NativeWebView Grid.Row="2" x:Name="Terminal" IsVisible="{Binding IsUnlocked}" />
</Grid>
</Grid>
<!-- Setup and unlock, over the top. -->
<!--
Setup and unlock. Last in the Panel, so it is above the app content in Avalonia's z-order — which
covers Avalonia-drawn content and nothing else. The terminal is collapsed rather than covered.
-->
<Border Background="#10131a" IsVisible="{Binding !IsUnlocked}">
<Panel>