Merge origin/main into claude/spelunk-tunnel

Port forwarding took host schema version 8 first, so the Spelunk route moves to 9 and is written after the forwards. A host may carry both.
This commit is contained in:
jaap-jan committed 2026-09-28 21:38:09 +02:00
commit 689ba6c1bf
44 files changed
+3187 -75

No files matched your search

+7 -1
View File
@@ -132,7 +132,8 @@ public sealed partial class DodoSshApp : Avalonia.Application
var keepAlive = new SessionKeepAlive(
workspace,
activeTransfers: () => viewModel.Transfers.ActiveTransfers,
holdsFileSession: () => viewModel.Transfers.HasLiveFileSession);
holdsFileSession: () => viewModel.Transfers.HasLiveFileSession,
listeningForwards: () => viewModel.ListeningForwardCount);
// The other end of the same wire: the workspace announces its own sessions ending, and the queue
// announces transfers appearing and finishing, and a Files session connecting or disconnecting.
@@ -148,6 +149,11 @@ public sealed partial class DodoSshApp : Avalonia.Application
// in the first place, which was precisely the promise this whole arrangement exists to keep.
viewModel.TerminalSessionOpened += (_, _) => keepAlive.Refresh();
// A forward starting, stopping or failing changes the notification's wording and nothing else — it
// rides a shell's connection, so the shell is already what holds the service up. The user is still
// entitled to know a phone in their pocket is holding ports open.
viewModel.ForwardsChanged += (_, _) => keepAlive.Refresh();
keepAlive.Refresh();
}
@@ -141,6 +141,11 @@ internal sealed class SessionForegroundService : Service
/// <param name="liveSessions">Shells with a live channel behind them.</param>
/// <param name="activeTransfers">Transfers still moving bytes.</param>
/// <param name="holdsFileSession">Whether the Files screen holds a live, idle SFTP connection.</param>
/// <param name="listeningForwards">
/// Port forwards listening over those shells. Named in the summary and nothing else: a forward rides a
/// shell's connection, so it cannot be the reason the process has to stay up — see
/// <see cref="SessionKeepAlive"/>.
/// </param>
/// <remarks>
/// Three outcomes, not the two a plain start-or-stop would have. Nothing live stops the service, as
/// always. Something live and the service not yet running starts it. Something live and the service
@@ -152,7 +157,7 @@ internal sealed class SessionForegroundService : Service
/// which needs no foreground-start permission at all. A foregrounded refresh still prefers a real
/// start even over a service that looks like it is running; the inline remark below is why.
/// </remarks>
public static void Reconcile(int liveSessions, int activeTransfers, bool holdsFileSession)
public static void Reconcile(int liveSessions, int activeTransfers, bool holdsFileSession, int listeningForwards)
{
var context = PhoneEnvironment.Require();
@@ -165,7 +170,7 @@ internal sealed class SessionForegroundService : Service
// The summary says what is actually held, counted rather than generic — the same principle the
// delete confirmations follow. "DodoSSH is running" would tell the user nothing they could act on.
var summary = Summarise(liveSessions, activeTransfers, holdsFileSession);
var summary = Summarise(liveSessions, activeTransfers, holdsFileSession, listeningForwards);
// In-place only while backgrounded, where it is the only legal move. Foregrounded, a real start is
// always allowed and is preferred even when `running` says the service is up: a disconnect followed
@@ -255,15 +260,22 @@ internal sealed class SessionForegroundService : Service
activity.RequestPermissions([postNotifications], NotificationPermissionRequestCode));
}
private static string Summarise(int liveSessions, int activeTransfers, bool holdsFileSession)
private static string Summarise(int liveSessions, int activeTransfers, bool holdsFileSession, int listeningForwards)
{
var parts = new List<string>(3);
var parts = new List<string>(4);
if (liveSessions > 0)
{
parts.Add(liveSessions == 1 ? "1 shell connected" : $"{liveSessions} shells connected");
}
// Beside the shells they run over, and only while one is: a count left over from a session that has
// just ended would be a receipt for ports nothing holds open any more.
if (liveSessions > 0 && listeningForwards > 0)
{
parts.Add(listeningForwards == 1 ? "1 port forwarded" : $"{listeningForwards} ports forwarded");
}
if (holdsFileSession)
{
parts.Add("Files connected");
@@ -24,12 +24,20 @@ namespace DodoSSH.Client.Android.Platform;
/// looked, to this class, exactly like nothing being open at all. <c>holdsFileSession</c> below is that
/// gap closed, read the same way the other two facts are: asked, not cached.
/// </para>
/// <para>
/// Listening port forwards are a fourth fact, and a different kind: they only change what the notification
/// says. A forward runs over a shell's connection and stops with it, so there is never a listening forward
/// without a live shell already holding the service up — and a count that could start the service on its own
/// would only ever be wrong, in the moment a forward's Stopped had not been heard yet. What they add is the
/// receipt: the user is entitled to know the phone is holding ports open, as well as shells.
/// </para>
/// </remarks>
internal sealed class SessionKeepAlive : IDisposable
{
private readonly TerminalWorkspace workspace;
private readonly Func<int> activeTransfers;
private readonly Func<bool> holdsFileSession;
private readonly Func<int> listeningForwards;
/// <param name="workspace">The live shells.</param>
/// <param name="activeTransfers">
@@ -40,11 +48,20 @@ internal sealed class SessionKeepAlive : IDisposable
/// Whether the Files screen holds a live SFTP connection with nothing moving on it — the idle-but-
/// connected case a transfer count alone would miss. See <c>TransfersViewModel.HasLiveFileSession</c>.
/// </param>
public SessionKeepAlive(TerminalWorkspace workspace, Func<int> activeTransfers, Func<bool> holdsFileSession)
/// <param name="listeningForwards">
/// How many port forwards are listening, across every tab. For the notification's wording only; see the
/// class remarks. See <c>MainWindowViewModel.ListeningForwardCount</c>.
/// </param>
public SessionKeepAlive(
TerminalWorkspace workspace,
Func<int> activeTransfers,
Func<bool> holdsFileSession,
Func<int> listeningForwards)
{
this.workspace = workspace;
this.activeTransfers = activeTransfers;
this.holdsFileSession = holdsFileSession;
this.listeningForwards = listeningForwards;
// Raised on whatever thread the workspace announced from — a continuation of the ended run, or the
// closer's own — which is fine: starting and stopping a service is a binder call and needs no
@@ -56,14 +73,15 @@ internal sealed class SessionKeepAlive : IDisposable
/// <summary>Re-reads the counts and starts or stops the service to match.</summary>
/// <remarks>
/// Called after anything that could change any of the three facts — opening a shell, closing a tab, a
/// transfer finishing, a Files connection opening or closing. Calling it when nothing changed is free:
/// Called after anything that could change any of the facts — opening a shell, closing a tab, a transfer
/// finishing, a Files connection opening or closing, a forward starting or stopping. Calling it when nothing changed is free:
/// reconciling to the state it is already in is either a redundant <c>startForegroundService</c> — or,
/// now, a redundant notification post — on a running service, or a <c>stopService</c> on a stopped one,
/// and Android treats all of those as no-ops.
/// </remarks>
public void Refresh() =>
SessionForegroundService.Reconcile(workspace.LiveSessionCount, activeTransfers(), holdsFileSession());
SessionForegroundService.Reconcile(
workspace.LiveSessionCount, activeTransfers(), holdsFileSession(), listeningForwards());
/// <inheritdoc />
public void Dispose()
@@ -72,7 +90,7 @@ internal sealed class SessionKeepAlive : IDisposable
// The notification goes with the composition root. Leaving it up over a process that is shutting
// down is how an SSH client acquires a reputation for a notification you cannot get rid of.
SessionForegroundService.Reconcile(0, 0, false);
SessionForegroundService.Reconcile(0, 0, false, 0);
}
private void OnSessionEnded(object? sender, TerminalSessionEndedEventArgs e) => Refresh();
@@ -189,14 +189,18 @@
◆ Port forwarding, stated rather than drawn.
The v2 design gives this hub a sixth entry and a full screen behind it: local, remote and dynamic
rules with toggles and byte counters. Nothing in this application forwards anything — ISshConnection
offers OpenShellAsync and nothing else — so every switch on that screen would be a control with no
effect and every counter a number with no source.
rules with toggles and byte counters. Forwarding is built and runs here as on the desktop — a host's
forwards start with every terminal opened to it — but it is not a destination, so it has no row. A
forward belongs to a host and runs with a session, and on this head the session's forwards are a
sheet off the terminal's bar: the ⇄ button, drawn for a tab that has some, lists them with a switch
each. See MainWindowViewModel.IsForwardsSheetOpen.
What the phone lacks is the editor: its host form has no PORT FORWARDS section yet, so forwards are
added on the desktop and arrive here with the host. The byte counters are not built anywhere;
SSH.NET keeps no count to draw.
It is a paragraph here rather than a missing row for the reason the desktop keeps TEAMS in its rail:
a destination that is quietly absent reads as a product that never intended it, and this one is
intended. SyncEntityType.PortForward = 9 is reserved on the wire and unused. See
docs/design-import-gaps.md.
a place somebody looks for a feature should say where it went. See docs/design-import-gaps.md.
-->
<Border Classes="card" Margin="6,16,6,0">
<StackPanel Spacing="7">
@@ -206,11 +210,11 @@
<TextBlock Classes="mono" FontSize="13.5" FontWeight="SemiBold"
Foreground="{StaticResource TextDim}" Text="Port forwarding" />
<Border Classes="tag outline" VerticalAlignment="Center">
<TextBlock Text="NOT BUILT" />
<TextBlock Text="IN THE TERMINAL" />
</Border>
</StackPanel>
<TextBlock Classes="body"
Text="A connection here opens one channel — a shell — and nothing else, so there is no tunnel for a rule to run through. The wire protocol reserves a slot for forwarding rules and no client writes one. Nothing on this screen is hidden by a setting; the feature is absent." />
Text="Forwards saved on a host start with every terminal opened to it, here as on the desktop. The ⇄ button in the terminal's bar lists them, with a switch each and the reason one could not start. They are added and edited in the desktop app's host editor; this phone runs them but has no editor for them yet." />
</StackPanel>
</Border>
@@ -579,7 +579,7 @@ internal sealed partial class PhoneShell : UserControl
/// <para>
/// <b>The connect menu is a second such guard, and it matters more than the first.</b> A terminal now
/// fills the screen — no header, no bottom bar — so while that menu is up this gesture is the only way
/// off it other than the scrim and CANCEL. It is checked before the terminal is dismissed for the
/// off it other than the scrim and CANCEL. The forwards sheet, raised from the same bar, shares the guard. It is checked before the terminal is dismissed for the
/// reason it is drawn over it: back takes the topmost thing, and dismissing the surface underneath a
/// menu would take two, neither of them the one being looked at.
/// </para>
@@ -598,13 +598,12 @@ internal sealed partial class PhoneShell : UserControl
return;
}
// The connect menu, which is raised from the terminal's own bar and is the topmost thing the phone
// draws while it is up. Ahead of the editors below because it is nearer, and ahead of leaving the
// terminal because a gesture that dismissed the surface underneath a menu would close two things at
// once — and the one the user was looking at would not be either of them.
if (current.IsConnectSheetOpen)
// The connect menu or the forwards sheet, which are raised from the terminal's own bar and are the
// topmost thing the phone draws while one is up. Ahead of the editors below because they are nearer,
// and ahead of leaving the terminal because a gesture that dismissed the surface underneath a sheet
// would close two things at once — and the one the user was looking at would not be either of them.
if (TryCloseATerminalSheet(current))
{
current.CloseConnectSheetCommand.Execute(null);
e.Handled = true;
return;
}
@@ -647,6 +646,31 @@ internal sealed partial class PhoneShell : UserControl
}
}
/// <summary>
/// Lowers the connect menu or the forwards sheet, whichever is up over the terminal.
/// </summary>
/// <returns>Whether one was closed, and so whether back has been spent.</returns>
/// <remarks>
/// Both are raised from the terminal's bar and the scrim under each covers that bar, so at most one is
/// ever open; the order below decides nothing.
/// </remarks>
private static bool TryCloseATerminalSheet(MainWindowViewModel current)
{
if (current.IsConnectSheetOpen)
{
current.CloseConnectSheetCommand.Execute(null);
return true;
}
if (current.IsForwardsSheetOpen)
{
current.CloseForwardsSheetCommand.Execute(null);
return true;
}
return false;
}
/// <summary>
/// Lowers whatever the hosts screen has raised over its list, topmost first.
/// </summary>
@@ -110,6 +110,34 @@
<Setter Property="Foreground" Value="{StaticResource Danger}" />
</Style>
<!--
── the forwards ──────────────────────────────────────────────────────────────────────────────────────
The desktop sidebar's state word, in the same three colours: green only while listening, the danger
text colour for a forward that could not start, faint for OFF and STARTING. The bar's ⇄ follows the
same rule for the failed case and is otherwise the colour of the icons beside it. Mono and 9.5, which
is this head's label lettering rather than the desktop's Montserrat, and its own family for the reason
the step captions above give.
-->
<Style Selector="TextBlock.fwdstate">
<Setter Property="Foreground" Value="{StaticResource TextFaint}" />
<Setter Property="FontFamily" Value="{StaticResource MonoFont}" />
<Setter Property="FontWeight" Value="SemiBold" />
<Setter Property="FontSize" Value="9.5" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
<Style Selector="TextBlock.fwdstate.live">
<Setter Property="Foreground" Value="{StaticResource Live}" />
</Style>
<Style Selector="TextBlock.fwdstate.failed">
<Setter Property="Foreground" Value="{StaticResource DangerText}" />
</Style>
<Style Selector="TextBlock.fwdglyph">
<Setter Property="Foreground" Value="{StaticResource TextDim}" />
</Style>
<Style Selector="TextBlock.fwdglyph.failed">
<Setter Property="Foreground" Value="{StaticResource DangerText}" />
</Style>
</UserControl.Styles>
<Panel>
@@ -139,7 +167,7 @@
job — see the remark on the header in PhoneShell.axaml. -->
<Border Grid.Row="0" Height="35" Background="{StaticResource DeepChrome}"
BorderBrush="{StaticResource Border}" BorderThickness="0,0,0,1">
<Grid ColumnDefinitions="Auto,*,Auto">
<Grid ColumnDefinitions="Auto,*,Auto,Auto">
<!--
Back, and it goes to the page this terminal was opened over rather than to Hosts by name. The
@@ -244,10 +272,37 @@
HOSTS, which is the only action on its screen; this one is not.
Click as well as Command, and the handler does one thing the command cannot: put the software
keyboard away. See OnConnectMenuRequested.
keyboard away. See OnSheetRequested.
-->
<Button Grid.Column="2" Classes="icon" Content="+" Height="34" Margin="0,0,4,0"
Click="OnConnectMenuRequested"
<!--
The selected tab's forwards, which is what lets this head start them at all: a phone opening
listeners it never shows you is worse than one opening none. Drawn only for a tab that has some, so
a host without forwards pays nothing for the feature in a 35-pixel bar.
The count beside the arrows is the listening ones, in the green that means "running" everywhere
else; the arrows themselves turn the danger colour when one could not start. The desktop can leave a
refusal in its sidebar for the eye to find, because the sidebar is always drawn. The sheet this opens
is not, so the button has to say it first.
Outside the ScrollViewer with +, for the reason both ends are: a tenth tab must not push it away.
Width is not pinned to Button.icon's 44, because "⇄ 12" is wider than that; 44 is its minimum.
-->
<Button Grid.Column="2" Classes="icon" Height="34" Width="NaN" MinWidth="44" Padding="8,0"
Click="OnSheetRequested"
Command="{Binding OpenForwardsSheetCommand}"
IsVisible="{Binding SelectedTab.HasForwards, FallbackValue=False}">
<StackPanel Orientation="Horizontal" Spacing="5" VerticalAlignment="Center">
<TextBlock Classes="fwdglyph" Classes.failed="{Binding SelectedTab.HasFailedForward, FallbackValue=False}"
Text="⇄" FontSize="16" VerticalAlignment="Center" />
<TextBlock Classes="mono" FontSize="12" FontWeight="SemiBold" Foreground="{StaticResource Live}"
VerticalAlignment="Center"
Text="{Binding SelectedTab.ListeningForwardCount, FallbackValue=''}"
IsVisible="{Binding SelectedTab.HasListeningForward, FallbackValue=False}" />
</StackPanel>
</Button>
<Button Grid.Column="3" Classes="icon" Content="+" Height="34" Margin="0,0,4,0"
Click="OnSheetRequested"
Command="{Binding OpenConnectSheetCommand}" />
</Grid>
</Border>
@@ -742,6 +797,75 @@
</Border>
</Panel>
<!-- ============ the forwards sheet ============ -->
<!--
The desktop sidebar's FORWARDS section, as a sheet: the selected tab's forwards as they run over its
session, bound to the same rows. Each row is its own switch, as there — tap a listening one to stop it,
an off or failed one to start it, a failed one being a retry because the port may have been freed.
The route is written under the notation rather than left to a tooltip, which is where the desktop
keeps it: a phone has no hover, and which end each port is on is exactly what people get backwards
about -L and -R. The reason a row failed sits under that again, as the desktop draws it.
The same shape as the connect sheet above, raised from the bar the same way, collapsing the renderer
the same way — see MainWindowViewModel.IsForwardsSheetOpen. It scrolls, capped at most of the display,
because a host may carry more forwards than fit, and a sheet that grew past the top of the screen would
put its own title out of reach.
Nothing here edits a forward, and there is no add row: this head's host editor has no PORT FORWARDS
section yet, and the desktop's Add forward row leads to one. The footer says where they are edited.
-->
<Panel IsVisible="{Binding IsForwardsSheetOpen}">
<Button Classes="scrim" Command="{Binding CloseForwardsSheetCommand}" />
<Border VerticalAlignment="Bottom" Background="{StaticResource Panel}"
BorderBrush="{StaticResource BorderMid}" BorderThickness="0,1,0,0"
CornerRadius="22,22,0,0" Padding="20,18,20,16">
<StackPanel Spacing="0">
<Border Width="38" Height="4" CornerRadius="2" Background="{StaticResource BorderMid}"
HorizontalAlignment="Center" Margin="0,0,0,16" />
<TextBlock Classes="title" Text="FORWARDS" FontSize="13" />
<TextBlock Classes="detail" FontSize="10.5" Margin="0,3,0,0"
Text="{Binding SelectedTab.Label, FallbackValue=''}" />
<ScrollViewer Margin="0,10,0,0" MaxHeight="420" HorizontalScrollBarVisibility="Disabled">
<ItemsControl ItemsSource="{Binding SelectedTab.Forwards}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:PortForwardViewModel">
<Button Classes="row" Padding="12,8" Command="{Binding ToggleCommand}">
<Grid ColumnDefinitions="*,Auto">
<StackPanel Grid.Column="0" Spacing="3" VerticalAlignment="Center">
<TextBlock Classes="mono" FontSize="13.5" FontWeight="SemiBold"
Text="{Binding Notation}" TextTrimming="CharacterEllipsis" />
<TextBlock Classes="detail" FontSize="10.5" TextWrapping="Wrap"
Text="{Binding Route}" />
<TextBlock Classes="detail" FontSize="10.5" TextWrapping="Wrap"
Foreground="{StaticResource TextDim}" Text="{Binding Detail}"
IsVisible="{Binding Detail, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" />
</StackPanel>
<TextBlock Grid.Column="1" Classes="fwdstate" Margin="12,0,0,0"
Text="{Binding StateText}"
Classes.live="{Binding IsListening}" Classes.failed="{Binding IsFailed}" />
</Grid>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<TextBlock Classes="body" Margin="0,10,0,0"
Text="Tap a forward to switch it off or on. Local and SOCKS forwards listen on this phone's localhost, where any app on it can connect, and every forward stops with this tab's connection. Forwards are saved on the host and edited in the desktop app; a change starts with the next connection." />
<Button Classes="secondary" Content="DONE" Margin="0,12,0,0"
Command="{Binding CloseForwardsSheetCommand}" />
</StackPanel>
</Border>
</Panel>
</Panel>
</UserControl>
@@ -210,10 +210,14 @@ internal sealed partial class TerminalScreen : UserControl
private void AdoptRenderer() => RendererFocus.Suppress(input.Acquire);
/// <summary>
/// Puts the keyboard away on the way to the connect menu.
/// Puts the keyboard away on the way to the connect menu or the forwards sheet.
/// </summary>
/// <remarks>
/// <para>
/// One handler for both buttons in the terminal's bar that raise a sheet, since what follows is true of
/// either: each is a panel at the bottom of the screen, which is where the keyboard is.
/// </para>
/// <para>
/// A handler beside the button's command rather than something the command does, because the command is
/// on the shared view model and this is a platform call: the desktop head has no software keyboard to
/// put away, and a shell view model that knew about Android's input-method manager would be the first
@@ -222,7 +226,7 @@ internal sealed partial class TerminalScreen : UserControl
/// <para>
/// <b>The keyboard is up in the ordinary case.</b> This button sits above a terminal somebody is typing
/// into, so the sheet it raises would otherwise arrive underneath a keyboard covering half the display —
/// and the three rows on it are the bottom half. Worse, the keyboard's inset shortens everything the
/// and the rows on it are the bottom half. Worse, the keyboard's inset shortens everything the
/// phone draws (see <c>PhoneShell.ApplyKeyboardInset</c>), so the sheet would be laid out into the
/// remaining strip rather than merely hidden behind it.
/// </para>
@@ -231,7 +235,7 @@ internal sealed partial class TerminalScreen : UserControl
/// what the other writes: this one talks to the platform and the command sets a flag, so they commute.
/// </para>
/// </remarks>
private void OnConnectMenuRequested(object? sender, RoutedEventArgs e) => SoftKeyboard.Hide();
private void OnSheetRequested(object? sender, RoutedEventArgs e) => SoftKeyboard.Hide();
/// <summary>
/// Takes the browser gestures back off a surface that is not a web page.