Merge branch 'fix/shell-notify': taskbar progress, OS notifications, shortcuts, job notices, badges, General settings

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 11:13:04 +00:00
commit 979a27e3d3
117 files changed
+1807 -190

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");
}
}
+20
View File
@@ -9,6 +9,26 @@
Title="{Binding WindowTitle}"
Width="1440" Height="900" MinWidth="1200" MinHeight="760"
WindowStartupLocation="CenterScreen">
<!-- The taskbar button mirrors the job bar (BRIEF §11.5); red while a failure waits on the Jobs screen. -->
<ui:TitanoWindow.TaskbarItemInfo>
<TaskbarItemInfo ProgressState="{Binding TaskbarState}" ProgressValue="{Binding TaskbarProgress}" />
</ui:TitanoWindow.TaskbarItemInfo>
<!-- Sections by keyboard, as the rail tooltips list them (BRIEF §12.1): Ctrl+1…6 down the rail, Ctrl+, for Settings. -->
<ui:TitanoWindow.InputBindings>
<KeyBinding Key="D1" Modifiers="Control" Command="{Binding NavigateCommand}" CommandParameter="{x:Static shell:SectionKey.Library}" />
<KeyBinding Key="D2" Modifiers="Control" Command="{Binding NavigateCommand}" CommandParameter="{x:Static shell:SectionKey.Import}" />
<KeyBinding Key="D3" Modifiers="Control" Command="{Binding NavigateCommand}" CommandParameter="{x:Static shell:SectionKey.Sequence}" />
<KeyBinding Key="D4" Modifiers="Control" Command="{Binding NavigateCommand}" CommandParameter="{x:Static shell:SectionKey.Archive}" />
<KeyBinding Key="D5" Modifiers="Control" Command="{Binding NavigateCommand}" CommandParameter="{x:Static shell:SectionKey.Jobs}" />
<KeyBinding Key="D6" Modifiers="Control" Command="{Binding NavigateCommand}" CommandParameter="{x:Static shell:SectionKey.Server}" />
<KeyBinding Key="NumPad1" Modifiers="Control" Command="{Binding NavigateCommand}" CommandParameter="{x:Static shell:SectionKey.Library}" />
<KeyBinding Key="NumPad2" Modifiers="Control" Command="{Binding NavigateCommand}" CommandParameter="{x:Static shell:SectionKey.Import}" />
<KeyBinding Key="NumPad3" Modifiers="Control" Command="{Binding NavigateCommand}" CommandParameter="{x:Static shell:SectionKey.Sequence}" />
<KeyBinding Key="NumPad4" Modifiers="Control" Command="{Binding NavigateCommand}" CommandParameter="{x:Static shell:SectionKey.Archive}" />
<KeyBinding Key="NumPad5" Modifiers="Control" Command="{Binding NavigateCommand}" CommandParameter="{x:Static shell:SectionKey.Jobs}" />
<KeyBinding Key="NumPad6" Modifiers="Control" Command="{Binding NavigateCommand}" CommandParameter="{x:Static shell:SectionKey.Server}" />
<KeyBinding Key="OemComma" Modifiers="Control" Command="{Binding NavigateCommand}" CommandParameter="{x:Static shell:SectionKey.Settings}" />
</ui:TitanoWindow.InputBindings>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
+44 -4
View File
@@ -9,9 +9,15 @@ using Titano.Ui.Controls;
namespace Titano.App.Shell;
/// <summary>
/// The client's window (BRIEF §12.1): rail, job bar, section, status strip, the first-run dialog and the toasts, which
/// also become Windows notifications while nobody sees the window (<see cref="OsNotifications"/>).
/// </summary>
public partial class MainWindow : TitanoWindow
{
private readonly ShellViewModel _shell;
private readonly OsNotifications _notifications;
private WindowState? _restoreTo;
public MainWindow(ShellViewModel shell)
{
@@ -24,10 +30,37 @@ public partial class MainWindow : TitanoWindow
if (e.PropertyName is nameof(ShellViewModel.IsConnected) or "") UpdateConnection();
if (e.PropertyName is nameof(ShellViewModel.IsWelcomeOpen) or "") FocusWelcome();
};
// Screenshots and tests run off screen and never activated: they must not reach the notification area.
_notifications = new OsNotifications(this, () => shell.Services.Settings.OsNotifications && !shell.Services.Environment.IsCapture, t => Toasts.Dismiss(t));
shell.PendingToasts.CollectionChanged += OnToastRequested;
Loaded += (_, _) => FocusWelcome();
RestorePlacement();
Closing += (_, _) => SavePlacement();
Closed += (_, _) => _notifications.Dispose();
}
/// <summary>Started at sign-in (Settings › General › Startup): the window waits minimised on the taskbar.</summary>
internal static bool StartsMinimized(IReadOnlyList<string> arguments) =>
arguments.Any(a => a.Equals(RunKeyStartWithWindows.MinimizedOption, StringComparison.OrdinalIgnoreCase));
/// <summary>Minimised until the user opens it; that first restore brings back the saved state (maximised or not).</summary>
internal void WaitMinimized(bool maximized)
{
WindowState = WindowState.Minimized;
_restoreTo = maximized ? WindowState.Maximized : WindowState.Normal;
}
/// <summary>The maximised flag to save: a window started minimised and never opened keeps the state it would come back to.</summary>
internal static bool SavesMaximized(WindowState state, WindowState? restoreTo) =>
state == WindowState.Maximized || (state == WindowState.Minimized && restoreTo == WindowState.Maximized);
/// <summary>The first restore of a window started minimised brings back the saved maximised state.</summary>
protected override void OnStateChanged(EventArgs e)
{
base.OnStateChanged(e);
if (_restoreTo is not { } state || WindowState == WindowState.Minimized) return;
_restoreTo = null;
if (WindowState != state) WindowState = state;
}
/// <summary>F6 moves the keyboard to the newest notification (as in Windows apps), Esc there dismisses it.</summary>
@@ -66,14 +99,21 @@ public partial class MainWindow : TitanoWindow
private void OnToastRequested(object? sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action != NotifyCollectionChangedAction.Add || e.NewItems is null) return;
foreach (Toast t in e.NewItems) Toasts.Show(t);
foreach (Toast t in e.NewItems)
{
Toasts.Show(t);
_notifications.Show(t);
}
Dispatcher.BeginInvoke(() => _shell.PendingToasts.Clear());
}
private void RestorePlacement()
{
if (_shell.Services.Environment.IsCapture) return;
var p = _shell.Services.Settings.Window;
if (p is null || p.Width < MinWidth || p.Height < MinHeight || _shell.Services.Environment.IsCapture) return;
var maximized = p?.Maximized == true;
if (StartsMinimized(Environment.GetCommandLineArgs())) WaitMinimized(maximized);
if (p is null || p.Width < MinWidth || p.Height < MinHeight) return;
var virtualScreen = new Rect(SystemParameters.VirtualScreenLeft, SystemParameters.VirtualScreenTop, SystemParameters.VirtualScreenWidth, SystemParameters.VirtualScreenHeight);
var rect = new Rect(p.Left, p.Top, p.Width, p.Height);
if (!virtualScreen.IntersectsWith(rect)) return;
@@ -82,7 +122,7 @@ public partial class MainWindow : TitanoWindow
Top = p.Top;
Width = p.Width;
Height = p.Height;
if (p.Maximized) WindowState = WindowState.Maximized;
if (maximized && _restoreTo is null) WindowState = WindowState.Maximized;
}
private void SavePlacement()
@@ -95,7 +135,7 @@ public partial class MainWindow : TitanoWindow
Top = b.Top,
Width = b.Width,
Height = b.Height,
Maximized = WindowState == WindowState.Maximized,
Maximized = SavesMaximized(WindowState, _restoreTo),
};
}
}
+129
View File
@@ -0,0 +1,129 @@
using System.Windows;
using Titano.Core.Localization;
using Titano.Ui.Controls;
using Titano.Ui.Interop;
namespace Titano.App.Shell;
/// <summary>
/// Windows notifications for the toasts nobody would see (BRIEF §12.1 "optional OS toast when minimised", §12.4 "Card
/// X detected — Import"): while the main window is minimised, hidden or behind another program, every toast also goes
/// to a tray balloon, which Windows 10/11 shows as a notification, when Settings › General allows it. Clicking it
/// brings the window back; it also runs the toast's action when the toast allows it
/// (<see cref="Toast.RunsFromNotification"/>) and it is the only notification shown, since Windows does not say which
/// of several was clicked. The tray icon exists only while such a notification can be clicked: it goes once a window
/// of Titano is active again. Create, use and dispose it on the UI thread.
/// </summary>
public sealed class OsNotifications : IDisposable
{
private const int MenuShow = 1;
private readonly Window _window;
private readonly Func<bool> _enabled;
private readonly Action<Toast> _dismiss;
private TrayIcon? _tray;
private Toast? _latest;
private int _shown;
private bool _disposed;
/// <param name="window">The main window, restored by a click.</param>
/// <param name="enabled">Settings › General › Notifications (never during screenshots and tests).</param>
/// <param name="dismiss">Closes the in-window toast whose action a click ran.</param>
public OsNotifications(Window window, Func<bool> enabled, Action<Toast> dismiss)
{
_window = window;
_enabled = enabled;
_dismiss = dismiss;
_window.Activated += OnActivated;
}
/// <summary>The tray icon is in the notification area (tests).</summary>
internal bool HasTrayIcon => _tray is not null;
/// <summary>Mirrors <paramref name="toast"/> as a Windows notification when nobody sees the window; true when it did.</summary>
public bool Show(Toast toast)
{
// A toast raised while the app closes (the window is hidden by then) needs no icon that would outlive it.
if (_disposed || !_enabled() || !IsUnseen(_window.WindowState, _window.IsVisible, AnyWindowActive())) return false;
_tray ??= new TrayIcon(Loc.L("Shell.AppName"), Menu, OnMenu, Restore, OnBalloonClicked);
_latest = toast;
_shown++;
_tray.ShowBalloon(toast.Title, BalloonText(toast), toast.IsError);
return true;
}
public void Dispose()
{
_disposed = true;
_window.Activated -= OnActivated;
RemoveIcon();
}
/// <summary>Nobody sees the main window: minimised, hidden, or no window of Titano has the foreground.</summary>
public static bool IsUnseen(WindowState state, bool isVisible, bool anyWindowActive) =>
state == WindowState.Minimized || !isVisible || !anyWindowActive;
/// <summary>
/// The notification's text: the toast's message, then the action a click on it runs ("Import"); the title alone
/// when there is neither (Windows needs a text to show a notification at all). An action a click does not run
/// waits in the window and is not offered here.
/// </summary>
public static string BalloonText(Toast toast)
{
ArgumentNullException.ThrowIfNull(toast);
var lines = new[] { toast.Message, toast.RunsFromNotification ? toast.ActionText : null }.Where(l => !string.IsNullOrWhiteSpace(l));
return string.Join(Environment.NewLine, lines) is { Length: > 0 } text ? text : toast.Title;
}
/// <summary>
/// A notification was clicked: the window comes back, and the toast's action runs when the toast allows it and
/// no other notification was shown since the icon appeared (Windows does not say which one was clicked).
/// </summary>
internal void OnBalloonClicked()
{
var toast = _shown == 1 ? _latest : null;
_latest = null;
Restore();
if (toast is not { RunsFromNotification: true, ActionCommand: { } command } || !command.CanExecute(null)) return;
command.Execute(null);
_dismiss(toast);
}
private static bool AnyWindowActive() => Application.Current?.Windows.OfType<Window>().Any(w => w.IsActive) ?? false;
private IReadOnlyList<TrayMenuItem> Menu() => [new(MenuShow, Loc.L("Shell.Tray.Show"))];
private void OnMenu(int id)
{
if (id == MenuShow) Restore();
}
/// <summary>The window as it was before it was minimised (maximised stays maximised), in front.</summary>
private void Restore()
{
_window.Show();
if (_window.WindowState == WindowState.Minimized) SystemCommands.RestoreWindow(_window);
_window.Activate();
}
/// <summary>
/// Back in front: the notifications have done their job. The icon goes after the current message, since activation
/// may come from a click the icon's own window is still handling, unless the window went to the background again.
/// </summary>
private void OnActivated(object? sender, EventArgs e)
{
if (_tray is null) return;
_window.Dispatcher.BeginInvoke(() =>
{
if (!IsUnseen(_window.WindowState, _window.IsVisible, AnyWindowActive())) RemoveIcon();
});
}
private void RemoveIcon()
{
_latest = null;
_shown = 0;
_tray?.Dispose();
_tray = null;
}
}
+36 -4
View File
@@ -1,5 +1,6 @@
using System.Collections.ObjectModel;
using System.Windows.Input;
using System.Windows.Shell;
using Titano.App.Infrastructure;
using Titano.App.Sections;
using Titano.Core.Diagnostics;
@@ -26,6 +27,7 @@ public sealed class ShellViewModel : LocalizedViewModel
private string? _serverName;
private int _jobCount;
private int _queuedCount;
private int _unseenFailures;
private WelcomeViewModel? _welcome;
private Guid? _currentSequenceId;
@@ -48,12 +50,13 @@ public sealed class ShellViewModel : LocalizedViewModel
Library.IsSelected = true;
Library.PropertyChanged += OnCurrentChanged;
// The rail and its shortcuts (Ctrl+1…6, Ctrl+,) navigate only while no first-run dialog covers the shell.
NavigateCommand = new RelayCommand(p =>
{
if (p is SectionViewModel s) Navigate(s.Key);
else if (p is SectionKey k) Navigate(k);
else if (p is string name && Enum.TryParse<SectionKey>(name, out var key)) Navigate(key);
});
}, _ => IsShellEnabled);
ToggleRailCommand = new RelayCommand(() => IsRailCollapsed = !IsRailCollapsed);
services.Server.PropertyChanged += (_, _) => SetConnection(services.Server.ServerName);
if (!_settings.FirstRunCompleted) _welcome = new WelcomeViewModel(this);
@@ -89,6 +92,7 @@ public sealed class ShellViewModel : LocalizedViewModel
if (!Set(ref _welcome, value)) return;
OnPropertyChanged(nameof(IsWelcomeOpen));
OnPropertyChanged(nameof(IsShellEnabled));
CommandManager.InvalidateRequerySuggested();
}
}
@@ -196,8 +200,20 @@ public sealed class ShellViewModel : LocalizedViewModel
public string JobAnnouncement => _jobActive && _jobName is not null ? _jobName : JobText;
/// <summary>
/// Updates the global job bar (and the taskbar progress through the window). <paramref name="name"/> says which job
/// it is without its progress ("Render: Harbour sunset"); null reads <paramref name="text"/>.
/// The taskbar button mirrors the job bar (BRIEF §11.5): the running job's progress, sliding while its total is
/// unknown; red while no job runs and a failure waits on the Jobs screen; nothing otherwise.
/// </summary>
public TaskbarItemProgressState TaskbarState =>
_jobActive ? _jobIndeterminate ? TaskbarItemProgressState.Indeterminate : TaskbarItemProgressState.Normal
: _unseenFailures > 0 ? TaskbarItemProgressState.Error
: TaskbarItemProgressState.None;
/// <summary>0…1 for <see cref="TaskbarState"/>; a waiting failure fills the button.</summary>
public double TaskbarProgress => _jobActive ? _jobProgress : _unseenFailures > 0 ? 1 : 0;
/// <summary>
/// Updates the global job bar and the taskbar button. <paramref name="name"/> says which job it is without its
/// progress ("Render: Harbour sunset"); null reads <paramref name="text"/>.
/// </summary>
public void SetJob(string? text, double progress, bool indeterminate = false, string? name = null)
{
@@ -208,6 +224,17 @@ public sealed class ShellViewModel : LocalizedViewModel
IsJobIndeterminate = indeterminate;
OnPropertyChanged(nameof(JobText));
OnPropertyChanged(nameof(JobAnnouncement));
OnPropertyChanged(nameof(TaskbarState));
OnPropertyChanged(nameof(TaskbarProgress));
}
/// <summary>Failed jobs not seen on the Jobs screen yet (the taskbar button turns red while no job runs).</summary>
public void SetUnseenFailures(int count)
{
if (_unseenFailures == count) return;
_unseenFailures = count;
OnPropertyChanged(nameof(TaskbarState));
OnPropertyChanged(nameof(TaskbarProgress));
}
// ---- Status strip ----
@@ -264,8 +291,10 @@ public sealed class ShellViewModel : LocalizedViewModel
/// <summary>
/// A one-line notice with one action (job done, update available). <paramref name="isError"/> marks something that
/// did not happen or failed: screen readers then say it at once instead of after what they are reading.
/// <paramref name="runsFromNotification"/>: a click on its Windows notification also runs the action (<see cref="Toast.RunsFromNotification"/>).
/// </summary>
public void Notify(string title, string? message = null, string? actionText = null, string? actionToolTip = null, Action? action = null, bool isError = false) =>
public void Notify(string title, string? message = null, string? actionText = null, string? actionToolTip = null, Action? action = null, bool isError = false,
bool runsFromNotification = false) =>
ShowToast(new Toast
{
Title = title,
@@ -274,6 +303,7 @@ public sealed class ShellViewModel : LocalizedViewModel
ActionToolTip = actionToolTip,
ActionCommand = action is null ? null : new RelayCommand(action),
IsError = isError,
RunsFromNotification = runsFromNotification,
});
/// <summary>Errors are one sentence saying what happened plus one action (BRIEF §0.2 rule 6); the details go to the log.</summary>
@@ -292,6 +322,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();