feat(app): taskbar progress, Windows notifications, job toasts, rail badges and section shortcuts

UI-05: the main window's TaskbarItemInfo mirrors the job bar (progress, sliding while
the total is unknown) and turns red while a failure waits on the Jobs screen.

UI-06: the Uploader's tray icon moves to Titano.Ui (Interop/TrayIcon, with a balloon
click callback and error balloons) and the Uploader keeps using it. While the main
window is minimised, hidden or behind another program, every toast (card inserted,
auto-import, job ended, server messages) also becomes a Windows notification; clicking
it restores the window and runs the toast's action. The icon exists only while such a
notification can be clicked. Settings › General gains Notifications (on by default)
and Startup: Start with Windows writes the HKCU Run value "Titano" with --minimized,
and the window then waits minimised on the taskbar.

UI-07: Ctrl+1…6 and Ctrl+, navigate from anywhere in the window, as the rail tooltips
say (not behind the first-run dialog). The editor's 1:1 view moves to Ctrl+Shift+1;
its tooltip key is renamed so no translation keeps the old shortcut.

UI-08: the Jobs screen raises one toast when a long operation ends (render, deep
analysis, verify, rebuild, maintenance, upload: Open; failures: Retry, or Import for a
failed import), whichever screen started it. Background work and scans end silently,
and a finished render of the sequence open in the editor is left to the editor's own
toast with its output file.

UI-10: the Jobs badge adds failures not seen on the Jobs screen yet; the Server badge
counts settings conflicts waiting for a choice.

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:32:39 +00:00
1 parent ec297914db
commit d25ecca64e
60 files changed
+836 -108

No files matched your search

+1 -1
View File
@@ -5,10 +5,10 @@ using System.Windows;
using System.Windows.Threading;
using Titano.Core.Diagnostics;
using Titano.Core.Localization;
using Titano.Ui.Interop;
using Titano.Ui.Mvvm;
using Titano.Ui.Theming;
using Titano.Uploader.Infrastructure;
using Titano.Uploader.Interop;
using Titano.Uploader.Server;
using Titano.Uploader.Shell;
using Titano.Uploader.Uploads;
-255
View File
@@ -1,255 +0,0 @@
using System.Runtime.InteropServices;
using System.Windows.Interop;
using Titano.Core.Diagnostics;
using Titano.Core.Localization;
namespace Titano.Uploader.Interop;
/// <summary>One entry of the tray menu; an id of 0 is a separator.</summary>
public readonly record struct TrayMenuItem(int Id, string? Text);
/// <summary>
/// Notification-area icon through <c>Shell_NotifyIconW</c>: the program icon from the executable's resources, a tooltip,
/// a native context menu and balloons. A hidden window receives the callbacks and re-adds the icon after Explorer restarts.
/// </summary>
public sealed unsafe partial class TrayIcon : IDisposable
{
private const uint NimAdd = 0;
private const uint NimModify = 1;
private const uint NimDelete = 2;
private const uint NifMessage = 0x1;
private const uint NifIcon = 0x2;
private const uint NifTip = 0x4;
private const uint NifInfo = 0x10;
private const uint NiifUser = 0x4;
private const int CallbackMessage = 0x8000 + 1; // WM_APP + 1
private const int WmContextMenu = 0x007B;
private const int WmLButtonUp = 0x0202;
private const int WmLButtonDblClk = 0x0203;
private const int WmRButtonUp = 0x0205;
private const int NinBalloonUserClick = 0x0405;
private const uint MfString = 0x0;
private const uint MfSeparator = 0x800;
private const uint TpmRightButton = 0x2;
private const uint TpmNoNotify = 0x80;
private const uint TpmReturnCmd = 0x100;
private const uint TpmLayoutRtl = 0x8000;
private readonly HwndSource _window;
private readonly IntPtr _icon;
private readonly bool _ownsIcon;
private readonly uint _taskbarCreated;
private readonly Func<IReadOnlyList<TrayMenuItem>> _menu;
private readonly Action<int> _command;
private readonly Action _show;
private string _toolTip;
private bool _added;
/// <param name="toolTip">Hover text (up to 127 characters).</param>
/// <param name="menu">Builds the context menu when it opens.</param>
/// <param name="command">Runs a chosen menu id.</param>
/// <param name="show">Left click or balloon click.</param>
public TrayIcon(string toolTip, Func<IReadOnlyList<TrayMenuItem>> menu, Action<int> command, Action show)
{
_toolTip = toolTip;
_menu = menu;
_command = command;
_show = show;
// A hidden top-level window: message-only windows miss the TaskbarCreated broadcast.
_window = new HwndSource(new HwndSourceParameters("TitanoUploaderTray") { Width = 0, Height = 0, WindowStyle = 0 });
_window.AddHook(WndProc);
_taskbarCreated = RegisterWindowMessageW("TaskbarCreated");
(_icon, _ownsIcon) = LoadProgramIcon();
Add();
}
public void SetToolTip(string text)
{
_toolTip = text;
var data = NewData(NifTip);
Copy(_toolTip, data.Tip, 128);
Notify(NimModify, &data);
}
/// <summary>Shows a balloon (a toast on Windows 10/11) with the program icon.</summary>
public void ShowBalloon(string title, string text)
{
var data = NewData(NifInfo);
Copy(title, data.InfoTitle, 64);
Copy(text, data.Info, 256);
data.InfoFlags = NiifUser;
Notify(NimModify, &data);
}
public void Dispose()
{
if (_added)
{
var data = NewData(0);
Notify(NimDelete, &data);
_added = false;
}
if (_ownsIcon) DestroyIcon(_icon);
_window.Dispose();
}
private void Add()
{
var data = NewData(NifMessage | NifIcon | NifTip);
data.CallbackMessage = CallbackMessage;
data.Icon = _icon;
Copy(_toolTip, data.Tip, 128);
_added = Notify(NimAdd, &data);
}
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == CallbackMessage)
{
switch ((int)(lParam.ToInt64() & 0xFFFF))
{
case WmLButtonUp or WmLButtonDblClk or NinBalloonUserClick:
_show();
break;
case WmRButtonUp or WmContextMenu:
ShowMenu();
break;
}
handled = true;
}
else if (_taskbarCreated != 0 && msg == (int)_taskbarCreated)
{
Add();
}
return IntPtr.Zero;
}
private void ShowMenu()
{
var menu = CreatePopupMenu();
if (menu == IntPtr.Zero) return;
try
{
foreach (var item in _menu())
{
if (item.Id == 0 || item.Text is null) AppendMenuW(menu, MfSeparator, 0, null);
else AppendMenuW(menu, MfString, (nuint)item.Id, item.Text);
}
GetCursorPos(out var point);
// Without foreground the menu would not close when the user clicks elsewhere.
SetForegroundWindow(_window.Handle);
// Right-to-left languages get a mirrored menu, as the window itself is (BRIEF §16).
var layout = Loc.IsRightToLeft ? TpmLayoutRtl : 0;
var chosen = TrackPopupMenuEx(menu, TpmReturnCmd | TpmRightButton | TpmNoNotify | layout, point.X, point.Y, _window.Handle, IntPtr.Zero);
PostMessageW(_window.Handle, 0, IntPtr.Zero, IntPtr.Zero);
if (chosen != 0) _command(chosen);
}
finally
{
DestroyMenu(menu);
}
}
private NotifyIconData NewData(uint flags) => new()
{
Size = (uint)sizeof(NotifyIconData),
Window = _window.Handle,
Id = 1,
Flags = flags,
};
private static bool Notify(uint message, NotifyIconData* data)
{
if (Shell_NotifyIconW(message, data)) return true;
Log.Info("tray", $"Shell_NotifyIcon({message}) failed");
return false;
}
private static void Copy(string text, char* destination, int capacity)
{
var length = Math.Min(text.Length, capacity - 1);
text.AsSpan(0, length).CopyTo(new Span<char>(destination, capacity));
destination[length] = '\0';
}
/// <summary>The generated titano-uploader icon embedded in the executable; the stock icon if it cannot be read.</summary>
private static (IntPtr Icon, bool Owned) LoadProgramIcon()
{
if (Environment.ProcessPath is { } exe)
{
IntPtr small;
if (ExtractIconExW(exe, 0, null, &small, 1) > 0 && small != IntPtr.Zero) return (small, true);
}
return (LoadIconW(IntPtr.Zero, 32512), false); // IDI_APPLICATION
}
[StructLayout(LayoutKind.Sequential)]
private struct NotifyIconData
{
public uint Size;
public IntPtr Window;
public uint Id;
public uint Flags;
public uint CallbackMessage;
public IntPtr Icon;
public fixed char Tip[128];
public uint State;
public uint StateMask;
public fixed char Info[256];
public uint TimeoutOrVersion;
public fixed char InfoTitle[64];
public uint InfoFlags;
public Guid Item;
public IntPtr BalloonIcon;
}
[StructLayout(LayoutKind.Sequential)]
private struct Point
{
public int X;
public int Y;
}
[LibraryImport("shell32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool Shell_NotifyIconW(uint message, NotifyIconData* data);
[LibraryImport("shell32.dll", StringMarshalling = StringMarshalling.Utf16)]
private static partial uint ExtractIconExW(string file, int index, IntPtr* large, IntPtr* small, uint count);
[LibraryImport("user32.dll")]
private static partial IntPtr LoadIconW(IntPtr instance, nint name);
[LibraryImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool DestroyIcon(IntPtr icon);
[LibraryImport("user32.dll", StringMarshalling = StringMarshalling.Utf16)]
private static partial uint RegisterWindowMessageW(string name);
[LibraryImport("user32.dll")]
private static partial IntPtr CreatePopupMenu();
[LibraryImport("user32.dll", StringMarshalling = StringMarshalling.Utf16)]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool AppendMenuW(IntPtr menu, uint flags, nuint id, string? text);
[LibraryImport("user32.dll")]
private static partial int TrackPopupMenuEx(IntPtr menu, uint flags, int x, int y, IntPtr window, IntPtr parameters);
[LibraryImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool DestroyMenu(IntPtr menu);
[LibraryImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool GetCursorPos(out Point point);
[LibraryImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool SetForegroundWindow(IntPtr window);
[LibraryImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static partial bool PostMessageW(IntPtr window, int message, IntPtr wParam, IntPtr lParam);
}