fix(app): exit without waiting for the UI thread, close the editor with the shell, cancel sign-in safely

DESK-1: SyncHost's dispose, session switch and stop now continue on the thread pool
(ConfigureAwait(false)) and keep the running agent in one reference. A signed-in user
whose archive is not polled no longer waits 10 s at every exit, after which the job
engine and the index were never closed.

DESK-7: ShellViewModel.Dispose disposes the Sequence section first, so the open
editor stops its runners and closes its source before the engine and the index go.

DESK-8: Cancel stays available while the server answers a sign-in. It now cancels
the request; an answer that still arrives changes nothing (the connection flow
ignores answers for a client it dropped), and a sign-in that completed just before
the cancel was handled is signed out again. The form no longer sets a result after
it closed, and an unexpected failure shows inline instead of escaping async void.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-12 09:29:58 +00:00
1 parent c11c996bc6
commit e4bbf11da9
8 files changed
+345 -35

No files matched your search

+32 -14
View File
@@ -1,6 +1,7 @@
using System.Windows;
using System.Windows.Automation;
using System.Windows.Automation.Peers;
using Titano.Core.Diagnostics;
using Titano.Ui.Controls;
namespace Titano.App.Shell;
@@ -9,16 +10,20 @@ namespace Titano.App.Shell;
/// The login form (BRIEF §12.7). It calls back the connection with the credentials and stays open with the
/// error sentence until the sign-in succeeds or the user cancels. The password never leaves the PasswordBox
/// except for that call. A failed sign-in is announced to screen readers and marks the password box (error border,
/// sentence as its help text) until the next attempt.
/// sentence as its help text) until the next attempt. Cancel stays available while the server answers: the form
/// closes at once and the connection drops the answer.
/// </summary>
public sealed partial class LoginDialog : TitanoWindow
{
private readonly Func<string, string, Task<string?>> _signIn;
private bool _pending;
private bool _closed;
private LoginDialog(string server, string? username, Func<string, string, Task<string?>> signIn)
{
_signIn = signIn;
InitializeComponent();
Closed += (_, _) => _closed = true;
ServerText.Text = server;
User.Text = username ?? string.Empty;
Loaded += (_, _) =>
@@ -41,28 +46,41 @@ public sealed partial class LoginDialog : TitanoWindow
private async void OnSignIn(object sender, RoutedEventArgs e)
{
if (_pending) return;
_pending = true;
SignIn.IsEnabled = false;
Error.Visibility = Visibility.Collapsed;
Field.SetError(Password, null);
string? error;
try
{
var error = await _signIn(User.Text, Password.Password);
if (error is null)
{
DialogResult = true;
return;
}
Error.Text = error;
Error.Visibility = Visibility.Visible;
Field.SetError(Password, error);
Password.Clear();
Password.Focus();
UIElementAutomationPeer.CreatePeerForElement(this)?.RaiseNotificationEvent(
AutomationNotificationKind.ActionCompleted, AutomationNotificationProcessing.ImportantMostRecent, error, "Titano.SignIn");
error = await _signIn(User.Text, Password.Password);
}
catch (Exception ex) when (ex is not OutOfMemoryException)
{
// Cancel ended the request: nobody waits for this answer any more.
if (_closed && ex is OperationCanceledException) return;
Log.Warning("server", "Sign-in failed", ex);
error = ErrorText.For(ex);
}
finally
{
_pending = false;
SignIn.IsEnabled = true;
}
// The form was cancelled or closed while the server answered: a result can no longer be set on it.
if (_closed) return;
if (error is null)
{
DialogResult = true;
return;
}
Error.Text = error;
Error.Visibility = Visibility.Visible;
Field.SetError(Password, error);
Password.Clear();
Password.Focus();
UIElementAutomationPeer.CreatePeerForElement(this)?.RaiseNotificationEvent(
AutomationNotificationKind.ActionCompleted, AutomationNotificationProcessing.ImportantMostRecent, error, "Titano.SignIn");
}
}
+2
View File
@@ -292,6 +292,8 @@ public sealed class ShellViewModel : LocalizedViewModel
public override void Dispose()
{
// The editor first: it stops its runners and closes its source before the engine and the index under it go.
Sequence.Dispose();
Jobs.Dispose();
Library.Dispose();
Import.Dispose();