fix(app): notification clicks run only what the toast names, batches speak once, warnings get badges

- Toast.RunsFromNotification: a click on a Windows notification restores the window and runs the toast's
  action only when the toast opts in (card detected: Import; interrupted import: Resume; job finished: Open;
  navigation to Import or Jobs) and it is the only notification shown since the icon appeared. Cancel, Undo
  and Retry stay in the window, and the notification text no longer offers them.
- Job endings are coalesced: finished jobs of one kind wait until no job of that kind the user waits for is
  queued or running, then one toast says how many finished ("12 jobs finished", action Jobs); failures of one
  update share one toast. Server > Upload all no longer raises one toast and one notification per sequence.
- Every failure that is not upkeep (scan, thumbnails, proxies, light analysis) is announced, including move,
  adopt and user downloads; finished moves and adoptions are announced too.
- Rail badges: Library counts the sequences with warnings (the Warnings filter), refreshed after analyses;
  Archive counts the index health lines that need attention.
- Tests: the balloon click path, the --minimized restore to a saved maximised window, batch and failure
  coalescing, and the new badges.

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 10:35:19 +00:00
1 parent 97c6484c74
commit 6417e2b3c2
15 files changed
+438 -64

No files matched your search

+13 -7
View File
@@ -43,6 +43,17 @@ public partial class MainWindow : TitanoWindow
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)
{
@@ -101,11 +112,7 @@ public partial class MainWindow : TitanoWindow
if (_shell.Services.Environment.IsCapture) return;
var p = _shell.Services.Settings.Window;
var maximized = p?.Maximized == true;
if (StartsMinimized(Environment.GetCommandLineArgs()))
{
WindowState = WindowState.Minimized;
_restoreTo = maximized ? WindowState.Maximized : WindowState.Normal;
}
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);
@@ -128,8 +135,7 @@ public partial class MainWindow : TitanoWindow
Top = b.Top,
Width = b.Width,
Height = b.Height,
// Started minimised and never opened: the saved state stays the one it would have been restored to.
Maximized = WindowState == WindowState.Maximized || (WindowState == WindowState.Minimized && _restoreTo == WindowState.Maximized),
Maximized = SavesMaximized(WindowState, _restoreTo),
};
}
}
+25 -15
View File
@@ -9,8 +9,10 @@ namespace Titano.App.Shell;
/// 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 and runs the toast's action. 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.
/// 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
{
@@ -21,6 +23,7 @@ public sealed class OsNotifications : IDisposable
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>
@@ -44,6 +47,7 @@ public sealed class OsNotifications : IDisposable
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;
}
@@ -60,16 +64,31 @@ public sealed class OsNotifications : IDisposable
state == WindowState.Minimized || !isVisible || !anyWindowActive;
/// <summary>
/// The notification's text: the toast's message, then its action ("Import"), which a click on it runs; the title
/// alone when there is neither (Windows needs a text to show a notification at all).
/// 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.ActionText }.Where(l => !string.IsNullOrWhiteSpace(l));
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"))];
@@ -87,16 +106,6 @@ public sealed class OsNotifications : IDisposable
_window.Activate();
}
private void OnBalloonClicked()
{
var toast = _latest;
_latest = null;
Restore();
if (toast?.ActionCommand is not { } command || !command.CanExecute(null)) return;
command.Execute(null);
_dismiss(toast);
}
/// <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.
@@ -113,6 +122,7 @@ public sealed class OsNotifications : IDisposable
private void RemoveIcon()
{
_latest = null;
_shown = 0;
_tray?.Dispose();
_tray = null;
}
+4 -1
View File
@@ -291,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,
@@ -301,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>