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:
60 files changed
+836
-108
No files matched your search
@@ -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" />
|
||||
|
||||
@@ -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,26 @@ 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>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 +88,25 @@ 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()))
|
||||
{
|
||||
WindowState = WindowState.Minimized;
|
||||
_restoreTo = maximized ? WindowState.Maximized : WindowState.Normal;
|
||||
}
|
||||
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 +115,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 +128,8 @@ public partial class MainWindow : TitanoWindow
|
||||
Top = b.Top,
|
||||
Width = b.Width,
|
||||
Height = b.Height,
|
||||
Maximized = WindowState == WindowState.Maximized,
|
||||
// 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),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
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 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.
|
||||
/// </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 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;
|
||||
_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 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).
|
||||
/// </summary>
|
||||
public static string BalloonText(Toast toast)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(toast);
|
||||
var lines = new[] { toast.Message, toast.ActionText }.Where(l => !string.IsNullOrWhiteSpace(l));
|
||||
return string.Join(Environment.NewLine, lines) is { Length: > 0 } text ? text : toast.Title;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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.
|
||||
/// </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;
|
||||
_tray?.Dispose();
|
||||
_tray = null;
|
||||
}
|
||||
}
|
||||
@@ -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 ----
|
||||
|
||||
Reference in new issue
Block a user