Desktop: stop the status bar's session timer when the shell ends

This commit is contained in:
jaap-jan committed 2026-10-02 13:54:24 +02:00
1 parent 619f49a35a
commit 22b4d82ba8
3 files changed
+29 -3

No files matched your search

@@ -4518,7 +4518,7 @@ internal sealed partial class MainWindowViewModel : ObservableObject, IAsyncDisp
{
if (Tabs.FirstOrDefault(tab => tab.SessionId == e.SessionId) is { } tab)
{
tab.Ended(e.Outcome.End, e.Outcome.Description);
tab.Ended(e.Outcome.End, e.Outcome.Description, clock.GetUtcNow());
// Only for the tab being looked at, which is what these three already ask. The rectangle does not
// change — a dead tab keeps its pane and its scrollback — but the status bar under it does, and
@@ -4998,7 +4998,12 @@ internal sealed partial class MainWindowViewModel : ObservableObject, IAsyncDisp
return null;
}
var elapsed = clock.GetUtcNow() - started;
// Up to the end, for a shell that has one: how long it ran, not how long ago it started.
var until = Surface is ShellSurface.Terminal && SelectedTab?.EndedAt is { } ended
? ended
: clock.GetUtcNow();
var elapsed = until - started;
if (elapsed < TimeSpan.Zero)
{
@@ -274,6 +274,15 @@ internal sealed partial class TerminalTabViewModel : ObservableObject
/// </remarks>
internal DateTimeOffset? StartedAt { get; set; }
/// <summary>When the session behind this tab ended, or null while it has not.</summary>
/// <remarks>
/// What stops the status bar's timer. It used to go on counting from <see cref="StartedAt"/> to now over a
/// shell that had exited an hour earlier, which made "how long that shell ran" — the fact the remark above
/// keeps <see cref="StartedAt"/> for — the one thing it no longer said. Stamped by <see cref="Ended"/> from
/// the shell's clock, and cleared whenever a new session takes the tab.
/// </remarks>
internal DateTimeOffset? EndedAt { get; private set; }
/// <summary>
/// The negotiated server-to-client cipher, for the status bar — or null while there is no session.
/// </summary>
@@ -620,6 +629,7 @@ internal sealed partial class TerminalTabViewModel : ObservableObject
// stale-fact failure this pair exists to remove.
EndReason = null;
EndDescription = null;
EndedAt = null;
IsLive = true;
State = TerminalTabState.Open;
@@ -679,13 +689,14 @@ internal sealed partial class TerminalTabViewModel : ObservableObject
/// live attempt dead. <see cref="Advance"/> guards its own reports for the same reason.
/// </para>
/// </remarks>
internal void Ended(SshSessionEnd end, string description)
internal void Ended(SshSessionEnd end, string description, DateTimeOffset at)
{
if (State is not TerminalTabState.Open)
{
return;
}
EndedAt ??= at;
EndReason = end;
EndDescription = description;
IsLive = false;
@@ -733,6 +744,7 @@ internal sealed partial class TerminalTabViewModel : ObservableObject
// Cleared with the session they were facts about. Keeping them would put the previous connection's
// cipher in the status bar beside a handshake that has not negotiated one yet.
StartedAt = null;
EndedAt = null;
Cipher = null;
HostKeyAlgorithm = null;
IdentityLabel = null;