refactor!: rename Titano to Chronos and move CI and releases to Gitea (#6)
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout and the system SQLite. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow; the throw-away server runs without durability) and pe-check. - Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR, 3 on the shared runner; the weekly performance gates keep theirs). BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #6.
This commit is contained in:
1 parent
c99842cc86
commit
f2b58522b9
1801 files changed
+11804
-10676
No files matched your search
@@ -0,0 +1,27 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Interop;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Interop;
|
||||
using Chronos.Core.Localization;
|
||||
|
||||
namespace Chronos.App.Shell;
|
||||
|
||||
/// <summary>Window-owned dialogs: the shell's folder and file pickers, confirmations and the login form.</summary>
|
||||
public sealed class AppDialogs : IAppDialogs
|
||||
{
|
||||
/// <summary>Owner of the dialogs; the main window once it exists.</summary>
|
||||
public Window? Owner { get; set; }
|
||||
|
||||
private IntPtr OwnerHandle => Owner is null ? IntPtr.Zero : new WindowInteropHelper(Owner).Handle;
|
||||
|
||||
public string? PickFolder(string title, string? initialFolder = null) => FileDialogs.PickFolder(OwnerHandle, title);
|
||||
|
||||
public string? PickJsonFile(string title) => FileDialogs.PickFile(OwnerHandle, title,
|
||||
[
|
||||
new FileFilter(Loc.L("Settings.Import.Filter"), "*.json"),
|
||||
]);
|
||||
|
||||
public bool Confirm(ConfirmRequest request) => ConfirmDialog.Ask(Owner, request);
|
||||
|
||||
public bool SignIn(string server, string? username, Func<string, string, Task<string?>> signIn) => LoginDialog.Ask(Owner, server, username, signIn);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace Chronos.App.Shell;
|
||||
|
||||
/// <summary>
|
||||
/// The client's own styles (<c>Shell/AppStyles.xaml</c>) and view templates. They build on the Chronos.Ui kit with
|
||||
/// StaticResource, so they are merged after <see cref="Ui.Theming.ThemeManager.Initialize"/> loaded the kit.
|
||||
/// </summary>
|
||||
public static class AppResources
|
||||
{
|
||||
private static readonly Uri Styles = new("pack://application:,,,/Chronos;component/Shell/AppStyles.xaml", UriKind.Absolute);
|
||||
|
||||
/// <summary>Merges the client styles into <paramref name="app"/> once.</summary>
|
||||
public static void Merge(Application app)
|
||||
{
|
||||
if (app.Resources.MergedDictionaries.Any(d => d.Source == Styles)) return;
|
||||
app.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = Styles });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Chronos.Ui.Controls;assembly=Chronos.Ui"
|
||||
xmlns:sys="clr-namespace:System;assembly=System.Runtime">
|
||||
<!--
|
||||
Styles shared by the client screens, built on the kit of Chronos.Ui (DESIGN.md §3–4). Brushes are DynamicResource;
|
||||
sizes come from Typography.xaml through the kit's StaticResources.
|
||||
-->
|
||||
|
||||
<!-- Label column text (116 px panels, 180 px Settings). -->
|
||||
<Style x:Key="Text.Label" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.TextMuted}" />
|
||||
<Setter Property="FontSize" Value="13" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="TextTrimming" Value="CharacterEllipsis" />
|
||||
<Setter Property="Margin" Value="0,0,14,0" />
|
||||
</Style>
|
||||
|
||||
<!-- Faint helper value next to a control ("of 32 GB installed"). -->
|
||||
<Style x:Key="Text.Hint" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.TextFaint}" />
|
||||
<Setter Property="FontSize" Value="13" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="TextTrimming" Value="CharacterEllipsis" />
|
||||
</Style>
|
||||
|
||||
<!-- Table header cell: 11 px faint. -->
|
||||
<Style x:Key="Text.Header" TargetType="TextBlock">
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.TextFaint}" />
|
||||
<Setter Property="FontSize" Value="11" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="TextTrimming" Value="CharacterEllipsis" />
|
||||
</Style>
|
||||
|
||||
<!-- Table cell: one line, tabular figures, ellipsis. -->
|
||||
<Style x:Key="Text.Cell" TargetType="TextBlock">
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="TextTrimming" Value="CharacterEllipsis" />
|
||||
<Setter Property="Typography.NumeralAlignment" Value="Tabular" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="Text.CellNumber" TargetType="TextBlock" BasedOn="{StaticResource Text.Cell}">
|
||||
<Setter Property="TextAlignment" Value="Right" />
|
||||
</Style>
|
||||
|
||||
<!-- Log tail: monospaced, muted, left to right in every language (paths, times, codes). -->
|
||||
<Style x:Key="Text.Log" TargetType="TextBlock">
|
||||
<Setter Property="FlowDirection" Value="LeftToRight" />
|
||||
<Setter Property="FontFamily" Value="{StaticResource Font.Mono}" />
|
||||
<Setter Property="FontSize" Value="12" />
|
||||
<Setter Property="LineHeight" Value="18" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.TextMuted}" />
|
||||
<Setter Property="TextWrapping" Value="Wrap" />
|
||||
</Style>
|
||||
|
||||
<!-- Table row container (DESIGN §4: 36–40 px, hover = Card fill, 1 px divider; selected = AccentSubtle). -->
|
||||
<Style x:Key="ListBoxItem.Row" TargetType="ListBoxItem">
|
||||
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Text}" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="Padding" Value="14,0" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ListBoxItem">
|
||||
<Border x:Name="Bd" Background="Transparent" BorderBrush="{DynamicResource Brush.Stroke}" BorderThickness="0,0,0,1" Padding="{TemplateBinding Padding}">
|
||||
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Brush.Card}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Brush.AccentSubtle}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsKeyboardFocused" Value="True">
|
||||
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource Brush.Accent}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- Row container without selection (Jobs, encoder tables): hover only. -->
|
||||
<Style x:Key="ListBoxItem.PlainRow" TargetType="ListBoxItem" BasedOn="{StaticResource ListBoxItem.Row}">
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="Padding" Value="0" />
|
||||
</Style>
|
||||
|
||||
<!-- Section list entry of Settings: 34 px, active = Card fill + 3 px accent edge (Settings.html). -->
|
||||
<Style x:Key="ListBoxItem.Section" TargetType="ListBoxItem">
|
||||
<Setter Property="FocusVisualStyle" Value="{StaticResource Focus.Inset}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.TextMuted}" />
|
||||
<Setter Property="Height" Value="34" />
|
||||
<Setter Property="Margin" Value="0,0,0,2" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ListBoxItem">
|
||||
<Border x:Name="Bd" Background="Transparent" CornerRadius="{StaticResource Radius.Control}">
|
||||
<Grid>
|
||||
<Border x:Name="Edge" Width="3" HorizontalAlignment="Left" CornerRadius="1.5" Margin="0,7" Background="{DynamicResource Brush.Accent}" Visibility="Hidden" />
|
||||
<ContentPresenter Margin="12,0" VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</Border>
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsMouseOver" Value="True">
|
||||
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Brush.Card}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Text}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsSelected" Value="True">
|
||||
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Brush.Card}" />
|
||||
<Setter TargetName="Edge" Property="Visibility" Value="Visible" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Text}" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsKeyboardFocused" Value="True">
|
||||
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource Brush.Card}" />
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
|
||||
<!-- Filter chip (Jobs.html): 30 px pill, accent border and text when chosen (bind Tag to the chosen state). -->
|
||||
<Style x:Key="Button.Chip" TargetType="Button" BasedOn="{StaticResource Button.Base}">
|
||||
<Setter Property="Height" Value="30" />
|
||||
<Setter Property="Padding" Value="12,0" />
|
||||
<Setter Property="ui:ControlState.CornerRadius" Value="15" />
|
||||
<Style.Triggers>
|
||||
<Trigger Property="Tag">
|
||||
<Trigger.Value>
|
||||
<sys:Boolean>True</sys:Boolean>
|
||||
</Trigger.Value>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource Brush.Accent}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource Brush.Accent}" />
|
||||
<Setter Property="ui:ControlState.HoverBorderBrush" Value="{DynamicResource Brush.Accent}" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<!-- Row action (26 px, DESIGN §4 tables). -->
|
||||
<Style x:Key="Button.Row" TargetType="Button" BasedOn="{StaticResource Button.Compact}">
|
||||
<Setter Property="Height" Value="26" />
|
||||
<Setter Property="Padding" Value="10,0" />
|
||||
<Setter Property="Margin" Value="0,0,6,0" />
|
||||
</Style>
|
||||
|
||||
<!-- Toolbar dropdown (Library filters): accent border while a filter is active (bind Tag to the active flag). -->
|
||||
<Style x:Key="ComboBox.Filter" TargetType="ComboBox" BasedOn="{StaticResource {x:Type ComboBox}}">
|
||||
<Setter Property="MinWidth" Value="88" />
|
||||
<Setter Property="MaxDropDownHeight" Value="420" />
|
||||
<Style.Triggers>
|
||||
<Trigger Property="Tag">
|
||||
<Trigger.Value>
|
||||
<sys:Boolean>True</sys:Boolean>
|
||||
</Trigger.Value>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource Brush.Accent}" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
<!-- Closed box shows BoxText ("Year"), the open list shows Label ("All years"). -->
|
||||
<DataTemplate x:Key="Template.FilterOption">
|
||||
<TextBlock x:Name="Text" Text="{Binding Label}" TextTrimming="CharacterEllipsis" VerticalAlignment="Center" />
|
||||
<DataTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ComboBoxItem}}" Value="{x:Null}">
|
||||
<Setter TargetName="Text" Property="Text" Value="{Binding BoxText}" />
|
||||
</DataTrigger>
|
||||
</DataTemplate.Triggers>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate x:Key="Template.Label">
|
||||
<TextBlock Text="{Binding Label}" TextTrimming="CharacterEllipsis" VerticalAlignment="Center" />
|
||||
</DataTemplate>
|
||||
|
||||
<!-- Panel title (Text.Section, 14/600) for sub-sections inside a panel. -->
|
||||
<Style x:Key="Text.PanelTitle" TargetType="TextBlock" BasedOn="{StaticResource Text.Section}" />
|
||||
|
||||
<!-- One Settings row: 180 px label column, then the controls (Settings.html grid; 14 px between rows). -->
|
||||
<Style x:Key="Setting.Row" TargetType="HeaderedContentControl">
|
||||
<Setter Property="Focusable" Value="False" />
|
||||
<Setter Property="Margin" Value="0,0,0,14" />
|
||||
<Setter Property="MinHeight" Value="32" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="HeaderedContentControl">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="{StaticResource Grid.SettingsLabelColumn}" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Text="{TemplateBinding Header}" Style="{StaticResource Text.Label}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="0,7,14,0" />
|
||||
<ContentPresenter Grid.Column="1" VerticalAlignment="Center" />
|
||||
</Grid>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
<Setter Property="VerticalContentAlignment" Value="Top" />
|
||||
</Style>
|
||||
|
||||
<!-- Path, address and template fields in Settings (360 px, DESIGN mockup), left to right in every language. -->
|
||||
<Style x:Key="TextBox.Setting" TargetType="TextBox" BasedOn="{StaticResource TextBox.Path}">
|
||||
<Setter Property="Width" Value="360" />
|
||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="TextBox.SettingMono" TargetType="TextBox" BasedOn="{StaticResource TextBox.Mono}">
|
||||
<Setter Property="Width" Value="360" />
|
||||
<Setter Property="HorizontalAlignment" Value="Left" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="TextBox.Number" TargetType="TextBox" BasedOn="{StaticResource {x:Type TextBox}}">
|
||||
<Setter Property="Width" Value="72" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Right" />
|
||||
<Setter Property="Typography.NumeralAlignment" Value="Tabular" />
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,30 @@
|
||||
<ui:ChronosWindow x:Class="Chronos.App.Shell.ConfirmDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Chronos.Ui.Controls;assembly=Chronos.Ui"
|
||||
xmlns:l="clr-namespace:Chronos.Ui.Localization;assembly=Chronos.Ui"
|
||||
Title="{l:Loc Shell.AppName}"
|
||||
IsDialog="True" ResizeMode="NoResize" SizeToContent="Height" Width="460"
|
||||
WindowStartupLocation="CenterOwner" ShowInTaskbar="False"
|
||||
AutomationProperties.Name="{Binding Heading}" AutomationProperties.HelpText="{Binding Message}">
|
||||
<!-- DESIGN §4 dialog: two buttons, safe action left and default, the action on the right. Screen readers hear the
|
||||
heading and the message as the dialog opens on the safe button. -->
|
||||
<StackPanel Margin="24,18,24,20">
|
||||
<TextBlock Text="{Binding Heading}" Style="{StaticResource Text.Title}" TextWrapping="Wrap" TextTrimming="None" />
|
||||
<TextBlock Text="{Binding Message}" Margin="0,8,0,0" Foreground="{DynamicResource Brush.TextMuted}" TextWrapping="Wrap" TextTrimming="None" LineHeight="18" />
|
||||
<Border Style="{StaticResource Border.Card}" Margin="0,16,0,0" Padding="12,10" ToolTip="{Binding DetailToolTip}"
|
||||
Visibility="{Binding Detail, Converter={x:Static ui:NullToCollapsedConverter.Instance}}">
|
||||
<TextBlock x:Name="DetailText" Text="{Binding Detail}" FontFamily="{StaticResource Font.Mono}" FontSize="{StaticResource Size.Secondary}" TextWrapping="Wrap" TextTrimming="None" LineHeight="18"
|
||||
FlowDirection="LeftToRight" />
|
||||
</Border>
|
||||
<StackPanel x:Name="Typing" Margin="0,16,0,0" Visibility="Collapsed">
|
||||
<TextBlock Text="{Binding TypedPrompt}" Foreground="{DynamicResource Brush.TextMuted}" TextWrapping="Wrap" />
|
||||
<TextBox x:Name="Typed" Margin="0,6,0,0" ui:Field.Placeholder="{Binding TypedConfirmation}" ToolTip="{Binding TypedPrompt}"
|
||||
AutomationProperties.Name="{Binding TypedPrompt}" TextChanged="OnTyped" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,24,0,0">
|
||||
<Button x:Name="Safe" Content="{Binding SafeText}" ToolTip="{Binding SafeToolTip}" IsDefault="True" IsCancel="True" MinWidth="96" Click="OnSafe" />
|
||||
<Button x:Name="Action" Content="{Binding ActionText}" ToolTip="{Binding ActionToolTip}" MinWidth="96" Margin="8,0,0,0" Click="OnAction" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</ui:ChronosWindow>
|
||||
@@ -0,0 +1,54 @@
|
||||
using System.Windows;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.Ui.Controls;
|
||||
|
||||
namespace Chronos.App.Shell;
|
||||
|
||||
/// <summary>Modal confirmation for trusting a certificate and for destructive actions (BRIEF §12.1).</summary>
|
||||
public sealed partial class ConfirmDialog : ChronosWindow
|
||||
{
|
||||
public ConfirmDialog(ConfirmRequest request)
|
||||
{
|
||||
DataContext = request;
|
||||
InitializeComponent();
|
||||
Action.SetResourceReference(StyleProperty, request.IsDestructive ? "Button.Destructive" : "Button.Primary");
|
||||
if (!request.IsDetailMonospaced)
|
||||
{
|
||||
// Names and sentences follow the reading direction; only fingerprints stay left to right.
|
||||
DetailText.SetResourceReference(FontFamilyProperty, "Font.Ui");
|
||||
DetailText.ClearValue(FlowDirectionProperty);
|
||||
}
|
||||
if (request.TypedConfirmation is null)
|
||||
{
|
||||
Loaded += (_, _) => Safe.Focus();
|
||||
return;
|
||||
}
|
||||
Typing.Visibility = Visibility.Visible;
|
||||
Loaded += (_, _) => Typed.Focus();
|
||||
EnableAction(false);
|
||||
}
|
||||
|
||||
/// <summary>True when the user chose the action.</summary>
|
||||
public static bool Ask(Window? owner, ConfirmRequest request)
|
||||
{
|
||||
var dialog = new ConfirmDialog(request);
|
||||
if (owner is { IsVisible: true }) dialog.Owner = owner;
|
||||
else dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
return dialog.ShowDialog() == true;
|
||||
}
|
||||
|
||||
private void OnSafe(object sender, RoutedEventArgs e) => DialogResult = false;
|
||||
|
||||
private void OnAction(object sender, RoutedEventArgs e) => DialogResult = true;
|
||||
|
||||
private void OnTyped(object sender, System.Windows.Controls.TextChangedEventArgs e) =>
|
||||
EnableAction(string.Equals(Typed.Text.Trim(), ((ConfirmRequest)DataContext).TypedConfirmation, StringComparison.CurrentCultureIgnoreCase));
|
||||
|
||||
/// <summary>The action waits for the typed confirmation; until then its tooltip says what to type (DESIGN §4 disabled states).</summary>
|
||||
private void EnableAction(bool enabled)
|
||||
{
|
||||
var request = (ConfirmRequest)DataContext;
|
||||
Action.IsEnabled = enabled;
|
||||
Action.ToolTip = enabled ? request.ActionToolTip : request.TypedPrompt;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Input;
|
||||
using Chronos.App.Settings;
|
||||
|
||||
namespace Chronos.App.Shell;
|
||||
|
||||
/// <summary>
|
||||
/// Attaches an <see cref="EditableField"/> to a text box (DESIGN §4 inputs): Enter commits, Esc reverts, leaving
|
||||
/// the field commits a valid value. Ctrl+Enter commits and still reaches the screen's shortcut (Import · Ctrl+Enter).
|
||||
/// </summary>
|
||||
public static class EditBehavior
|
||||
{
|
||||
public static readonly DependencyProperty FieldProperty = DependencyProperty.RegisterAttached(
|
||||
"Field", typeof(EditableField), typeof(EditBehavior), new PropertyMetadata(null, OnFieldChanged));
|
||||
|
||||
public static EditableField? GetField(DependencyObject d) => (EditableField?)d.GetValue(FieldProperty);
|
||||
|
||||
public static void SetField(DependencyObject d, EditableField? value) => d.SetValue(FieldProperty, value);
|
||||
|
||||
private static void OnFieldChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is not TextBox box) return;
|
||||
box.PreviewKeyDown -= OnKeyDown;
|
||||
box.LostKeyboardFocus -= OnLostFocus;
|
||||
if (e.NewValue is null) return;
|
||||
box.PreviewKeyDown += OnKeyDown;
|
||||
box.LostKeyboardFocus += OnLostFocus;
|
||||
}
|
||||
|
||||
private static void OnKeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
if (sender is not TextBox box || GetField(box) is not { } field) return;
|
||||
if (e.Key == Key.Enter)
|
||||
{
|
||||
field.Commit();
|
||||
box.SelectAll();
|
||||
e.Handled = Keyboard.Modifiers != ModifierKeys.Control;
|
||||
}
|
||||
else if (e.Key == Key.Escape)
|
||||
{
|
||||
field.Revert();
|
||||
box.SelectAll();
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
|
||||
private static void OnLostFocus(object sender, KeyboardFocusChangedEventArgs e)
|
||||
{
|
||||
if (sender is TextBox box && GetField(box) is { HasErrors: false } field) field.Commit();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Visible when the bound value's text equals the converter parameter (settings pages).</summary>
|
||||
public sealed class EqualsToVisibilityConverter : IValueConverter
|
||||
{
|
||||
public static EqualsToVisibilityConverter Instance { get; } = new();
|
||||
|
||||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) =>
|
||||
string.Equals(value?.ToString(), parameter?.ToString(), StringComparison.Ordinal) ? Visibility.Visible : Visibility.Collapsed;
|
||||
|
||||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => throw new NotSupportedException();
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using Chronos.Core.Archiving;
|
||||
using Chronos.Core.Import;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Core.Render;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Sync;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Protocol.Client;
|
||||
|
||||
namespace Chronos.App.Shell;
|
||||
|
||||
/// <summary>
|
||||
/// The sentence an error toast shows (BRIEF §0.2: one sentence saying what happened plus one action). Only failures
|
||||
/// that carry a catalog sentence say what happened; anything else (framework and OS messages, often technical
|
||||
/// English) reads "Something went wrong." and stays in the log.
|
||||
/// </summary>
|
||||
public static class ErrorText
|
||||
{
|
||||
public static string For(Exception ex) => Describe(Unwrap(ex)) ?? Loc.L("Errors.Unexpected");
|
||||
|
||||
/// <summary>
|
||||
/// A request to the signed-in server failed: the server's own sentence when it answered, else what the reply's status
|
||||
/// means (a proxy in front of it), that it does not answer (refused, timed out, dropped) or that its certificate is no
|
||||
/// longer trusted.
|
||||
/// </summary>
|
||||
public static string ForServer(Exception ex)
|
||||
{
|
||||
ex = Unwrap(ex);
|
||||
return Describe(ex) ?? ex switch
|
||||
{
|
||||
UntrustedCertificateException => Loc.L("Server.Error.Untrusted"),
|
||||
HttpRequestException or IOException or OperationCanceledException or TimeoutException => Loc.L("Server.Error.Unreachable"),
|
||||
_ => Loc.L("Errors.Unexpected"),
|
||||
};
|
||||
}
|
||||
|
||||
private static string? Describe(Exception ex) => ex switch
|
||||
{
|
||||
LeaseUnavailableException or ArchiveOfflineException or NewerFormatException or ImportSourceUnavailableException
|
||||
or CopyVerificationException or StaleRenamePlanException or SyncConflictChangedException => ex.Message,
|
||||
// The server words its errors in the client's language (Accept-Language).
|
||||
ChronosApiException api when FromServer(api.Error) => api.Error.Message,
|
||||
// Any other reply (a reverse proxy's 502 page while the server restarts, its 413 for a large body, a bare 500) holds
|
||||
// only the HTTP reason phrase, in English: say what its status means.
|
||||
ChronosApiException api => api.Status switch
|
||||
{
|
||||
HttpStatusCode.RequestEntityTooLarge => Loc.L("Server.Error.TooLarge"),
|
||||
HttpStatusCode.TooManyRequests => Loc.L("Server.Error.RateLimited"),
|
||||
_ when api.IsTransient => Loc.L("Server.Error.Unreachable"),
|
||||
>= HttpStatusCode.InternalServerError => Loc.L("Server.Error.Internal"),
|
||||
_ => null,
|
||||
},
|
||||
RenderException render => Loc.Get(render.ReasonKey, Loc.Culture) is null ? null : Loc.L(render.ReasonKey, [.. render.Args]),
|
||||
_ => null,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// An error the server wrote as its JSON, with its own sentence. <c>ChronosClient</c> codes any other reply
|
||||
/// <c>http_<status></c> with the reason phrase as its message, and JSON of another shape has no code.
|
||||
/// </summary>
|
||||
private static bool FromServer(ApiError error) =>
|
||||
error.Code is { } code && !code.StartsWith("http_", StringComparison.Ordinal) && !string.IsNullOrWhiteSpace(error.Message);
|
||||
|
||||
/// <summary>Awaited tasks and reflection wrap the real failure in one layer or more.</summary>
|
||||
private static Exception Unwrap(Exception ex)
|
||||
{
|
||||
while (ex is AggregateException { InnerExceptions.Count: 1 } or TargetInvocationException && ex.InnerException is { } inner) ex = inner;
|
||||
return ex;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<ui:ChronosWindow x:Class="Chronos.App.Shell.LoginDialog"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Chronos.Ui.Controls;assembly=Chronos.Ui"
|
||||
xmlns:l="clr-namespace:Chronos.Ui.Localization;assembly=Chronos.Ui"
|
||||
Title="{l:Loc Shell.AppName}"
|
||||
IsDialog="True" ResizeMode="NoResize" SizeToContent="Height" Width="440"
|
||||
WindowStartupLocation="CenterOwner" ShowInTaskbar="False" AutomationProperties.Name="{l:Loc Server.Login.Title}">
|
||||
<!-- BRIEF §12.7 login modal: the server is already identified and its certificate trusted. -->
|
||||
<StackPanel Margin="24,18,24,20">
|
||||
<TextBlock Text="{l:Loc Server.Login.Title}" Style="{StaticResource Text.Title}" />
|
||||
<TextBlock x:Name="ServerText" Margin="0,4,0,0" Style="{StaticResource Text.Secondary}" FlowDirection="LeftToRight" HorizontalAlignment="Left" />
|
||||
<Grid Margin="0,18,0,0">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" MinWidth="92" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="10" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Text="{l:Loc Server.Login.User}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,0,12,0" />
|
||||
<TextBox x:Name="User" Grid.Column="1" ToolTip="{l:Loc Tooltips.Server.LoginUser}" AutomationProperties.Name="{l:Loc Server.Login.User}" />
|
||||
<TextBlock Grid.Row="2" Text="{l:Loc Server.Login.Password}" Foreground="{DynamicResource Brush.TextMuted}" Margin="0,0,12,0" />
|
||||
<PasswordBox x:Name="Password" Grid.Row="2" Grid.Column="1" ToolTip="{l:Loc Tooltips.Server.LoginPassword}" AutomationProperties.Name="{l:Loc Server.Login.Password}" />
|
||||
</Grid>
|
||||
<ui:StatusGlyph x:Name="Error" Kind="Error" Margin="0,12,0,0" FontSize="{StaticResource Size.Secondary}" Visibility="Collapsed" />
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,22,0,0">
|
||||
<Button Content="{l:Loc Server.Login.Cancel}" ToolTip="{l:Loc Tooltips.Server.LoginCancel}" IsCancel="True" MinWidth="96" Click="OnCancel" />
|
||||
<Button x:Name="SignIn" Style="{StaticResource Button.Primary}" Content="{l:Loc Server.Login.SignIn}" ToolTip="{l:Loc Tooltips.Server.SignIn}" IsDefault="True" MinWidth="96" Margin="8,0,0,0" Click="OnSignIn" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</ui:ChronosWindow>
|
||||
@@ -0,0 +1,86 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Automation;
|
||||
using System.Windows.Automation.Peers;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Ui.Controls;
|
||||
|
||||
namespace Chronos.App.Shell;
|
||||
|
||||
/// <summary>
|
||||
/// 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. Cancel stays available while the server answers: the form
|
||||
/// closes at once and the connection drops the answer.
|
||||
/// </summary>
|
||||
public sealed partial class LoginDialog : ChronosWindow
|
||||
{
|
||||
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 += (_, _) =>
|
||||
{
|
||||
if (User.Text.Length == 0) User.Focus();
|
||||
else Password.Focus();
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>True when the user signed in.</summary>
|
||||
public static bool Ask(Window? owner, string server, string? username, Func<string, string, Task<string?>> signIn)
|
||||
{
|
||||
var dialog = new LoginDialog(server, username, signIn);
|
||||
if (owner is { IsVisible: true }) dialog.Owner = owner;
|
||||
else dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||
return dialog.ShowDialog() == true;
|
||||
}
|
||||
|
||||
private void OnCancel(object sender, RoutedEventArgs e) => DialogResult = false;
|
||||
|
||||
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
|
||||
{
|
||||
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, "Chronos.SignIn");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
<ui:ChronosWindow x:Class="Chronos.App.Shell.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:ui="clr-namespace:Chronos.Ui.Controls;assembly=Chronos.Ui"
|
||||
xmlns:l="clr-namespace:Chronos.Ui.Localization;assembly=Chronos.Ui"
|
||||
xmlns:shell="clr-namespace:Chronos.App.Shell"
|
||||
xmlns:infra="clr-namespace:Chronos.App.Infrastructure"
|
||||
xmlns:s="clr-namespace:Chronos.App.Sections"
|
||||
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:ChronosWindow.TaskbarItemInfo>
|
||||
<TaskbarItemInfo ProgressState="{Binding TaskbarState}" ProgressValue="{Binding TaskbarProgress}" />
|
||||
</ui:ChronosWindow.TaskbarItemInfo>
|
||||
<!-- Sections by keyboard, as the rail tooltips list them (BRIEF §12.1): Ctrl+1…6 down the rail, Ctrl+, for Settings. -->
|
||||
<ui:ChronosWindow.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.Edit}" />
|
||||
<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.Edit}" />
|
||||
<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}" />
|
||||
<!-- The rail's names or its icons alone (owner review 1). -->
|
||||
<KeyBinding Key="B" Modifiers="Control" Command="{Binding ToggleRailCommand}" />
|
||||
</ui:ChronosWindow.InputBindings>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- Navigation rail: full names, collapsible to icons (BRIEF §12.1; owner review 1): 200 px with names, 48 px of icons
|
||||
whose tooltips name their section, by ≡ or Ctrl+B, and the choice is kept. While the first-run dialog is open the
|
||||
shell behind it takes no input. The buttons of both lists form one group (GroupName); their check binds one way,
|
||||
the section the shell navigates to (a GroupName spans every window not yet on screen). -->
|
||||
<Border x:Name="Rail" Background="{DynamicResource Brush.Chrome}" ui:NavRail.IsCollapsed="{Binding IsRailCollapsed}"
|
||||
IsEnabled="{Binding IsShellEnabled}">
|
||||
<Border.Style>
|
||||
<Style TargetType="Border">
|
||||
<Setter Property="Width" Value="{StaticResource Width.Rail}" />
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsRailCollapsed}" Value="True">
|
||||
<Setter Property="Width" Value="{StaticResource Width.RailCollapsed}" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Border.Style>
|
||||
<DockPanel Margin="8,8,8,8" LastChildFill="False">
|
||||
<Button DockPanel.Dock="Top" Style="{StaticResource Button.IconSubtle}" HorizontalAlignment="Left" Margin="0,0,0,6"
|
||||
ui:ButtonIcon.Glyph="{StaticResource Icon.Menu}" Command="{Binding ToggleRailCommand}"
|
||||
ToolTip="{Binding RailToggleToolTip}" AutomationProperties.Name="{Binding RailToggleName}" />
|
||||
<!-- The tooltip names the section while the rail shows icons alone; screen readers hear the name once, then what it is for. -->
|
||||
<ItemsControl DockPanel.Dock="Top" ItemsSource="{Binding TopSections}" Focusable="False">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type shell:SectionViewModel}">
|
||||
<ui:NavRailButton GroupName="Rail" Glyph="{Binding Glyph}" Content="{Binding Label}" Badge="{Binding Badge}"
|
||||
IsChecked="{Binding IsSelected, Mode=OneWay}" ToolTip="{Binding RailToolTip}" AutomationProperties.Name="{Binding Label}"
|
||||
AutomationProperties.HelpText="{Binding ToolTip}"
|
||||
Command="{Binding DataContext.NavigateCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding}" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<ItemsControl DockPanel.Dock="Bottom" ItemsSource="{Binding BottomSections}" Focusable="False">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type shell:SectionViewModel}">
|
||||
<ui:NavRailButton GroupName="Rail" Glyph="{Binding Glyph}" Content="{Binding Label}" Badge="{Binding Badge}"
|
||||
IsChecked="{Binding IsSelected, Mode=OneWay}" ToolTip="{Binding RailToolTip}" AutomationProperties.Name="{Binding Label}"
|
||||
AutomationProperties.HelpText="{Binding ToolTip}"
|
||||
Command="{Binding DataContext.NavigateCommand, RelativeSource={RelativeSource AncestorType=ItemsControl}}" CommandParameter="{Binding}" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
</DockPanel>
|
||||
</Border>
|
||||
|
||||
<Grid Grid.Column="1" IsEnabled="{Binding IsShellEnabled}">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Job bar (DESIGN §4): current job, progress, time left, pause; "Ready" when idle, hidden when idle in the editor.
|
||||
Screen readers hear which job starts and when the queue empties, not its progress ticks. -->
|
||||
<ui:JobBar x:Name="JobBar" Text="{Binding JobText}" Progress="{Binding JobProgress}" IsActive="{Binding IsJobActive}" IsIndeterminate="{Binding IsJobIndeterminate}"
|
||||
StopCommand="{Binding StopJobCommand}" StopToolTip="{l:Loc Tooltips.Shell.PauseJob}" StopName="{l:Loc Shell.JobBar.Pause}" ActionGlyph="{StaticResource Icon.Pause}"
|
||||
Visibility="{Binding IsJobBarVisible, Converter={StaticResource BoolToVisibility}}"
|
||||
AutomationProperties.LiveSetting="Polite" infra:LiveRegion.Text="{Binding JobAnnouncement}" />
|
||||
|
||||
<ContentControl Grid.Row="1" Content="{Binding Current}" Focusable="False" />
|
||||
|
||||
<!-- Status strip -->
|
||||
<Border Grid.Row="2" Height="30" Background="{DynamicResource Brush.Chrome}" Padding="20,0">
|
||||
<StackPanel Orientation="Horizontal" TextElement.FontSize="12" TextElement.Foreground="{DynamicResource Brush.TextMuted}">
|
||||
<TextBlock Text="{Binding SequencesText}" Margin="0,0,18,0" VerticalAlignment="Center" />
|
||||
<TextBlock Text="{Binding PhotosText}" Margin="0,0,18,0" VerticalAlignment="Center" />
|
||||
<TextBlock Text="{Binding StorageText}" Margin="0,0,18,0" VerticalAlignment="Center" />
|
||||
<TextBlock x:Name="Connection" Text="{Binding ConnectionText}" Margin="0,0,18,0" VerticalAlignment="Center"
|
||||
AutomationProperties.LiveSetting="Polite" infra:LiveRegion.Text="{Binding ConnectionText}" />
|
||||
<TextBlock Text="{Binding JobsText}" VerticalAlignment="Center" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<!-- First run (Welcome.html): the shell dimmed behind one dialog that keeps the keyboard. -->
|
||||
<Grid x:Name="WelcomeOverlay" Grid.ColumnSpan="2" Visibility="{Binding IsWelcomeOpen, Converter={StaticResource BoolToVisibility}}"
|
||||
KeyboardNavigation.TabNavigation="Cycle" KeyboardNavigation.ControlTabNavigation="Cycle" KeyboardNavigation.DirectionalNavigation="Contained">
|
||||
<Border Background="{DynamicResource Brush.Scrim}" />
|
||||
<s:WelcomeView DataContext="{Binding Welcome}" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,114,0,0"
|
||||
AutomationProperties.Name="{l:Loc Shell.Welcome.Title}" />
|
||||
</Grid>
|
||||
|
||||
<!-- Above the first-run dialog too, so a card inserted meanwhile can still be acted on (Welcome.html). -->
|
||||
<ui:ToastHost x:Name="Toasts" Grid.ColumnSpan="2" />
|
||||
</Grid>
|
||||
</ui:ChronosWindow>
|
||||
@@ -0,0 +1,148 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.Ui.Controls;
|
||||
|
||||
namespace Chronos.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 : ChronosWindow
|
||||
{
|
||||
private readonly ShellViewModel _shell;
|
||||
private readonly OsNotifications _notifications;
|
||||
private WindowState? _restoreTo;
|
||||
|
||||
public MainWindow(ShellViewModel shell)
|
||||
{
|
||||
_shell = shell;
|
||||
DataContext = shell;
|
||||
InitializeComponent();
|
||||
UpdateConnection();
|
||||
shell.PropertyChanged += (_, e) =>
|
||||
{
|
||||
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>
|
||||
protected override void OnKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnKeyDown(e);
|
||||
if (!e.Handled && e.Key == Key.F6 && Keyboard.Modifiers == ModifierKeys.None) e.Handled = Toasts.FocusNewest();
|
||||
}
|
||||
|
||||
/// <summary>A held Ctrl+B toggles the rail once, not at the keyboard's repeat rate.</summary>
|
||||
protected override void OnPreviewKeyDown(KeyEventArgs e)
|
||||
{
|
||||
base.OnPreviewKeyDown(e);
|
||||
if (e.IsRepeat && e.Key == Key.B && Keyboard.Modifiers == ModifierKeys.Control) e.Handled = true;
|
||||
}
|
||||
|
||||
private void UpdateConnection() =>
|
||||
Connection.SetResourceReference(TextBlock.ForegroundProperty, _shell.IsConnected ? "Brush.Accent" : "Brush.TextMuted");
|
||||
|
||||
/// <summary>The first-run dialog takes the keyboard on its chosen option once it is on screen.</summary>
|
||||
private void FocusWelcome()
|
||||
{
|
||||
if (!_shell.IsWelcomeOpen) return;
|
||||
Dispatcher.BeginInvoke(DispatcherPriority.Loaded, () =>
|
||||
{
|
||||
if (!_shell.IsWelcomeOpen || !IsLoaded) return;
|
||||
if (FindChecked(WelcomeOverlay) is { } choice) choice.Focus();
|
||||
else WelcomeOverlay.MoveFocus(new TraversalRequest(FocusNavigationDirection.First));
|
||||
});
|
||||
}
|
||||
|
||||
private static RadioButton? FindChecked(DependencyObject root)
|
||||
{
|
||||
for (var i = 0; i < VisualTreeHelper.GetChildrenCount(root); i++)
|
||||
{
|
||||
var child = VisualTreeHelper.GetChild(root, i);
|
||||
if (child is RadioButton { IsChecked: true } radio) return radio;
|
||||
if (FindChecked(child) is { } nested) return nested;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
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);
|
||||
_notifications.Show(t);
|
||||
}
|
||||
Dispatcher.BeginInvoke(() => _shell.PendingToasts.Clear());
|
||||
}
|
||||
|
||||
private void RestorePlacement()
|
||||
{
|
||||
if (_shell.Services.Environment.IsCapture) return;
|
||||
var p = _shell.Services.Settings.Window;
|
||||
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;
|
||||
WindowStartupLocation = WindowStartupLocation.Manual;
|
||||
Left = p.Left;
|
||||
Top = p.Top;
|
||||
Width = p.Width;
|
||||
Height = p.Height;
|
||||
if (maximized && _restoreTo is null) WindowState = WindowState.Maximized;
|
||||
}
|
||||
|
||||
private void SavePlacement()
|
||||
{
|
||||
if (_shell.Services.Environment.IsCapture) return;
|
||||
var b = RestoreBounds;
|
||||
_shell.Services.Settings.Window = new AppSettings.WindowPlacement
|
||||
{
|
||||
Left = b.Left,
|
||||
Top = b.Top,
|
||||
Width = b.Width,
|
||||
Height = b.Height,
|
||||
Maximized = SavesMaximized(WindowState, _restoreTo),
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
using System.Windows;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Ui.Controls;
|
||||
using Chronos.Ui.Interop;
|
||||
|
||||
namespace Chronos.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 Chronos 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 Chronos 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,462 @@
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Threading;
|
||||
using Chronos.App.Archiving;
|
||||
using Chronos.App.DesignTime;
|
||||
using Chronos.App.Editor;
|
||||
using Chronos.App.Import;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Library;
|
||||
using Chronos.App.Server;
|
||||
using Chronos.App.Settings;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Ui.Controls;
|
||||
using Chronos.Ui.Theming;
|
||||
|
||||
namespace Chronos.App.Shell;
|
||||
|
||||
/// <summary>
|
||||
/// <c>Chronos.exe --capture <dir></c>: renders every client screen at 1440×900 in the dark and light themes to
|
||||
/// <c><screen>-<theme>.png</c> from <see cref="SampleData"/> (first run on an empty index, then a populated
|
||||
/// one, then the sync table with transfers, a conflict and its confirmation, then the sequence editor on an archive
|
||||
/// sequence and on a server sequence with proxies, its server job and a read-only account), plus the Library, the
|
||||
/// editor's Exposure tab and the import plan in Arabic (<c>*-rtl-dark.png</c>, right to left), for visual review,
|
||||
/// the pixel diff against <c>tests/visual/baselines</c> and phase reports (BRIEF §20.2), then exits. The pictures are
|
||||
/// the same on any day and machine: the clock stands at <see cref="SampleData.Now"/>, formats are English and nothing
|
||||
/// animates.
|
||||
/// </summary>
|
||||
public static class ScreenCapture
|
||||
{
|
||||
private static readonly AppTheme[] Themes = [AppTheme.Dark, AppTheme.Light];
|
||||
|
||||
public static async Task RunAsync(MainWindow window, ShellViewModel shell, SampleData sample, string directory)
|
||||
{
|
||||
var written = 0;
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
AppClock.Freeze(SampleData.Now);
|
||||
CultureInfo.CurrentCulture = CultureInfo.DefaultThreadCurrentCulture = CultureInfo.GetCultureInfo("en");
|
||||
Motion.SetIsEnabled(window, false);
|
||||
window.WindowStartupLocation = WindowStartupLocation.Manual;
|
||||
window.Left = -20000;
|
||||
window.Top = -20000;
|
||||
window.Width = 1440;
|
||||
window.Height = 900;
|
||||
window.ShowActivated = false;
|
||||
window.ShowInTaskbar = false;
|
||||
window.Show();
|
||||
|
||||
// First run: empty index, nothing connected, the welcome dialog over the empty Library.
|
||||
await sample.OpenEmptyAsync();
|
||||
await shell.StartAsync();
|
||||
foreach (var theme in Themes)
|
||||
{
|
||||
ThemeManager.Apply(theme);
|
||||
shell.Navigate(SectionKey.Library);
|
||||
shell.ShowWelcome();
|
||||
shell.Welcome!.ShowDiscovered(new Server.DiscoveredServer("Studio NAS", "https://nas.local:8443"));
|
||||
written += await SaveAsync(window, directory, "welcome", theme);
|
||||
shell.CompleteWelcome();
|
||||
written += await SaveAsync(window, directory, "library-empty", theme);
|
||||
shell.Navigate(SectionKey.Server);
|
||||
written += await SaveAsync(window, directory, "server-signedout", theme);
|
||||
}
|
||||
|
||||
// A populated archive, jobs in every state and a signed-in server.
|
||||
await sample.FillAsync();
|
||||
await shell.Library.RefreshAsync();
|
||||
await shell.Jobs.ReloadAsync();
|
||||
await shell.Services.Server.RestoreAsync();
|
||||
await shell.Services.Sync.RefreshAsync();
|
||||
await shell.Server.Sync.ReloadAsync();
|
||||
// The server's sequences without a copy here join the Library as remote cards.
|
||||
await shell.Library.RefreshAsync();
|
||||
shell.About.SetResult(null);
|
||||
await shell.Settings.DetectEncodersAsync();
|
||||
await shell.Settings.SelfTestAsync();
|
||||
await shell.Settings.DetectFormatsAsync(refresh: false);
|
||||
|
||||
foreach (var theme in Themes)
|
||||
{
|
||||
ThemeManager.Apply(theme);
|
||||
|
||||
shell.Library.LayoutIndex = 0;
|
||||
shell.Library.ClearSelectionCommand.Execute(null);
|
||||
shell.Navigate(SectionKey.Library);
|
||||
written += await SaveAsync(window, directory, "library", theme, waitForThumbnails: shell);
|
||||
if (shell.Library.Items.Count > 0) shell.Library.Items[0].IsSelected = true;
|
||||
written += await SaveAsync(window, directory, "library-selection", theme, waitForThumbnails: shell);
|
||||
shell.Library.LayoutIndex = 1;
|
||||
written += await SaveAsync(window, directory, "library-list", theme, waitForThumbnails: shell);
|
||||
shell.Library.LayoutIndex = 0;
|
||||
shell.Library.ClearSelectionCommand.Execute(null);
|
||||
shell.IsRailCollapsed = true;
|
||||
written += await SaveAsync(window, directory, "library-rail-collapsed", theme, waitForThumbnails: shell);
|
||||
shell.IsRailCollapsed = false;
|
||||
written += await CaptureLibraryScenesAsync(window, shell, directory, theme);
|
||||
|
||||
shell.Navigate(SectionKey.Jobs);
|
||||
if (shell.Jobs.Rows.Count > 0) shell.Jobs.Rows[0].IsExpanded = true;
|
||||
written += await SaveAsync(window, directory, "jobs", theme);
|
||||
|
||||
shell.Navigate(SectionKey.Server);
|
||||
written += await SaveAsync(window, directory, "server", theme);
|
||||
|
||||
shell.Navigate(SectionKey.Settings);
|
||||
foreach (var page in Enum.GetValues<SettingsPage>())
|
||||
{
|
||||
shell.Settings.Page = page;
|
||||
written += await SaveAsync(window, directory, "settings-" + page.ToString().ToLowerInvariant(), theme);
|
||||
}
|
||||
|
||||
shell.Navigate(SectionKey.About);
|
||||
written += await SaveAsync(window, directory, "about", theme);
|
||||
|
||||
// Edit with no sequence open: the picker (owner review 1, R7).
|
||||
shell.Navigate(SectionKey.Edit);
|
||||
await shell.Sequence.Picker.Loading;
|
||||
written += await SaveAsync(window, directory, "edit-picker", theme, waitForThumbnails: shell);
|
||||
|
||||
foreach (var state in ImportScenes.States)
|
||||
{
|
||||
DismissToasts(window);
|
||||
await ImportScenes.ShowAsync(shell, state);
|
||||
if (!ImportScenes.ShowsToast(state)) DismissToasts(window);
|
||||
written += await SaveAsync(window, directory, "import-" + state, theme);
|
||||
}
|
||||
DismissToasts(window);
|
||||
foreach (var view in ArchiveScenes.Views)
|
||||
{
|
||||
await ArchiveScenes.ShowAsync(shell, view);
|
||||
written += await SaveAsync(window, directory, "archive-" + view, theme);
|
||||
}
|
||||
}
|
||||
// The sync table with proxies kept here and transfers in every state, then filtered to the conflict, then the
|
||||
// conflict's confirmation (after the other screens, so the Jobs capture keeps its own sample).
|
||||
await sample.CacheProxiesAsync();
|
||||
await sample.FillSyncAsync();
|
||||
await shell.Server.Sync.ReloadAsync();
|
||||
// The job bar follows the upload the sync sample runs.
|
||||
await shell.Jobs.ReloadAsync();
|
||||
foreach (var theme in Themes)
|
||||
{
|
||||
ThemeManager.Apply(theme);
|
||||
shell.Navigate(SectionKey.Server);
|
||||
SelectSyncFilter(shell, SyncFilter.All);
|
||||
written += await SaveAsync(window, directory, "server-sync", theme);
|
||||
SelectSyncFilter(shell, SyncFilter.Conflicts);
|
||||
written += await SaveAsync(window, directory, "server-conflict", theme);
|
||||
if (shell.Server.Sync.Rows.FirstOrDefault() is { } conflict)
|
||||
written += await SaveDialogAsync(new ConfirmDialog(SyncTableViewModel.ConflictRequest(conflict.Entry, SyncAction.KeepMine)), directory,
|
||||
"server-conflict-confirm", theme);
|
||||
SelectSyncFilter(shell, SyncFilter.All);
|
||||
}
|
||||
|
||||
written += await CaptureEditorAsync(window, shell, sample, directory);
|
||||
written += await CaptureRemoteEditorAsync(window, shell, sample, directory);
|
||||
Log.Info("capture", $"{written} screenshot(s) written to {Path.GetFullPath(directory)}");
|
||||
if (written == 0) Environment.ExitCode = 1;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("capture", "Capture failed", ex);
|
||||
Environment.ExitCode = 1;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Application.Current.Shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <c>library-timeline</c>, <c>library-mass</c> (the selection with the whole bar), <c>library-delete</c> (the dry run
|
||||
/// of deleting that selection, behind its typed confirmation), <c>library-remote</c> (the server's sequences as
|
||||
/// remote cards) and <c>library-viewname</c> (Save view), then the Library as it was.
|
||||
/// </summary>
|
||||
private static async Task<int> CaptureLibraryScenesAsync(MainWindow window, ShellViewModel shell, string directory, AppTheme theme)
|
||||
{
|
||||
var written = 0;
|
||||
foreach (var scene in LibraryScenes.Scenes)
|
||||
{
|
||||
DismissToasts(window);
|
||||
await LibraryScenes.ShowAsync(shell, scene);
|
||||
written += await SaveAsync(window, directory, "library-" + scene, theme, waitForThumbnails: shell);
|
||||
if (scene == "mass" && await LibraryScenes.DeleteRequestAsync(shell) is { } request)
|
||||
written += await SaveDialogAsync(new ConfirmDialog(request), directory, "library-delete", theme);
|
||||
}
|
||||
shell.Library.Dialog?.CloseCommand.Execute(null);
|
||||
shell.Library.ClearSelectionCommand.Execute(null);
|
||||
shell.Library.ClearFiltersCommand.Execute(null);
|
||||
shell.Library.LayoutIndex = 0;
|
||||
await shell.Library.RefreshAsync();
|
||||
return written;
|
||||
}
|
||||
|
||||
private static void SelectSyncFilter(ShellViewModel shell, SyncFilter filter) =>
|
||||
shell.Server.Sync.Chips.First(c => c.Filter == filter).SelectCommand.Execute(null);
|
||||
|
||||
/// <summary>A dialog shown off screen, saved, then closed.</summary>
|
||||
private static async Task<int> SaveDialogAsync(Window dialog, string directory, string screen, AppTheme theme)
|
||||
{
|
||||
dialog.WindowStartupLocation = WindowStartupLocation.Manual;
|
||||
dialog.Left = -20000;
|
||||
dialog.Top = -20000;
|
||||
dialog.ShowActivated = false;
|
||||
dialog.ShowInTaskbar = false;
|
||||
Motion.SetIsEnabled(dialog, false);
|
||||
dialog.Show();
|
||||
try
|
||||
{
|
||||
return await SaveAsync(dialog, directory, screen, theme);
|
||||
}
|
||||
finally
|
||||
{
|
||||
dialog.Close();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The editor on the synthetic sunset: every step of the Edit path in both themes (<c>edit-<step>-<theme>.png</c>,
|
||||
/// the Camera step with a keyframe selected, the Export step as Export.html with the crop mask and no compare), then
|
||||
/// the preview overlays, the waveform, the "what changed" toast of Optimise all, the picker over the open sequence
|
||||
/// (<c>edit-change</c>), the Export step of the sequence once the server has it (Sync on) with two "Save both" copies
|
||||
/// to restore, and the Analysis step while the analysis runs (<c>edit-busy</c>).
|
||||
/// </summary>
|
||||
private static async Task<int> CaptureEditorAsync(MainWindow window, ShellViewModel shell, SampleData sample, string directory)
|
||||
{
|
||||
var written = 0;
|
||||
var id = await sample.FillEditorAsync();
|
||||
shell.OpenSequence(id);
|
||||
await shell.Sequence.OpenAsync(id);
|
||||
if (shell.Sequence.Editor is not { } editor)
|
||||
{
|
||||
Log.Warning("capture", "The editor sample did not open");
|
||||
return 0;
|
||||
}
|
||||
foreach (var camera in editor.Tabs.OfType<CameraTab>()) camera.SelectedKey = 1;
|
||||
foreach (var theme in Themes)
|
||||
{
|
||||
ThemeManager.Apply(theme);
|
||||
foreach (var tab in editor.Tabs)
|
||||
{
|
||||
editor.SelectedTab = tab;
|
||||
editor.IsCompare = tab is not ExportTab;
|
||||
editor.CurrentIndex = tab is ExportTab ? 40 : 45;
|
||||
written += await SaveEditorAsync(window, editor, directory, "edit-" + tab.Key.ToLowerInvariant(), theme);
|
||||
}
|
||||
|
||||
editor.SelectedTab = editor.Exposure;
|
||||
editor.IsCompare = true;
|
||||
editor.ShowVectors = editor.ShowRegions = true;
|
||||
written += await SaveEditorAsync(window, editor, directory, "edit-exposure-overlays", theme);
|
||||
editor.ShowVectors = editor.ShowRegions = false;
|
||||
editor.Exposure.ChartMode = ExposureChart.Waveform;
|
||||
written += await SaveEditorAsync(window, editor, directory, "edit-exposure-waveform", theme);
|
||||
editor.Exposure.ChartMode = ExposureChart.Luminance;
|
||||
|
||||
editor.OptimiseAllCommand.Execute(null);
|
||||
written += await SaveEditorAsync(window, editor, directory, "edit-optimise", theme);
|
||||
editor.Session.Undo();
|
||||
foreach (var toast in window.Toasts.Toasts.ToList()) window.Toasts.Dismiss(toast);
|
||||
|
||||
// Change sequence: the picker over the open sequence, which stays open behind it until another opens.
|
||||
shell.Sequence.ChangeSequenceCommand.Execute(null);
|
||||
await shell.Sequence.Picker.Loading;
|
||||
written += await SaveAsync(window, directory, "edit-change", theme, waitForThumbnails: shell);
|
||||
shell.Sequence.CancelPickCommand.Execute(null);
|
||||
}
|
||||
|
||||
// The server has the sequence (Sync can be ticked) and two copies of this PC's settings were kept by "Save both".
|
||||
await sample.KeepEditorCopiesAsync(id);
|
||||
await editor.Session.ReloadAsync();
|
||||
await editor.RefreshSyncGateAsync();
|
||||
var export = editor.Tabs.OfType<ExportTab>().Single();
|
||||
export.SyncToServer = true;
|
||||
editor.SelectedTab = export;
|
||||
editor.IsCompare = false;
|
||||
foreach (var theme in Themes)
|
||||
{
|
||||
ThemeManager.Apply(theme);
|
||||
written += await SaveEditorAsync(window, editor, directory, "edit-export-copies", theme);
|
||||
}
|
||||
export.SyncToServer = false;
|
||||
editor.SelectedTab = editor.Exposure;
|
||||
editor.IsCompare = true;
|
||||
|
||||
written += await CaptureRightToLeftAsync(window, shell, editor, directory);
|
||||
|
||||
// Last, as it stays: an analysis of the sequence running (settings disabled, viewing tools live), on the step that follows it.
|
||||
await sample.MarkAnalysingAsync(id);
|
||||
await editor.AttachJobsAsync();
|
||||
editor.SelectedTab = editor.Analysis;
|
||||
// The job bar shows the analysis, the one job running.
|
||||
await shell.Jobs.ReloadAsync();
|
||||
foreach (var theme in Themes)
|
||||
{
|
||||
ThemeManager.Apply(theme);
|
||||
written += await SaveEditorAsync(window, editor, directory, "edit-busy", theme);
|
||||
}
|
||||
return written;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Library, the editor's Exposure tab and the import plan in Arabic, dark: the layout mirrors while photos,
|
||||
/// charts, the filmstrip and templates stay left to right. English is restored whatever happens.
|
||||
/// </summary>
|
||||
private static async Task<int> CaptureRightToLeftAsync(MainWindow window, ShellViewModel shell, EditorViewModel editor, string directory)
|
||||
{
|
||||
var written = 0;
|
||||
var frame = editor.CurrentIndex;
|
||||
ThemeManager.Apply(AppTheme.Dark);
|
||||
UiLanguage.Apply("ar");
|
||||
try
|
||||
{
|
||||
DismissToasts(window);
|
||||
shell.Navigate(SectionKey.Library);
|
||||
written += await SaveAsync(window, directory, "library-rtl", AppTheme.Dark, waitForThumbnails: shell);
|
||||
|
||||
shell.Navigate(SectionKey.Edit);
|
||||
editor.SelectedTab = editor.Exposure;
|
||||
editor.IsCompare = true;
|
||||
editor.CurrentIndex = 45;
|
||||
written += await SaveEditorAsync(window, editor, directory, "edit-exposure-rtl", AppTheme.Dark);
|
||||
|
||||
await ImportScenes.ShowAsync(shell, "plan");
|
||||
DismissToasts(window);
|
||||
written += await SaveAsync(window, directory, "import-plan-rtl", AppTheme.Dark);
|
||||
}
|
||||
finally
|
||||
{
|
||||
UiLanguage.Apply("en");
|
||||
}
|
||||
shell.Navigate(SectionKey.Edit);
|
||||
editor.CurrentIndex = frame;
|
||||
return written;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A server sequence open with this PC's proxies (Sunrise over Superga, cached by the sync captures): the server in
|
||||
/// the header, the preview from the proxies, the project from the server (<c>edit-remote</c>); its Export tab,
|
||||
/// where the server picks the encoder and keeps the renders (<c>edit-remote-export</c>); a render running on the
|
||||
/// server with its bar and Cancel (<c>edit-remote-running</c>); then, last as it stays, the sequence opened by an
|
||||
/// account without the Edit right (<c>edit-remote-readonly</c>).
|
||||
/// </summary>
|
||||
private static async Task<int> CaptureRemoteEditorAsync(MainWindow window, ShellViewModel shell, SampleData sample, string directory)
|
||||
{
|
||||
var written = 0;
|
||||
var id = sample.ProxiedSequenceId;
|
||||
shell.OpenSequence(id);
|
||||
await shell.Sequence.OpenAsync(id);
|
||||
if (shell.Sequence.Editor is not { IsRemote: true } editor)
|
||||
{
|
||||
Log.Warning("capture", "The server sequence did not open in the editor");
|
||||
return 0;
|
||||
}
|
||||
DismissToasts(window);
|
||||
var export = editor.Tabs.OfType<ExportTab>().Single();
|
||||
foreach (var theme in Themes)
|
||||
{
|
||||
ThemeManager.Apply(theme);
|
||||
editor.SelectedTab = editor.Exposure;
|
||||
editor.IsCompare = true;
|
||||
written += await SaveEditorAsync(window, editor, directory, "edit-remote", theme);
|
||||
editor.SelectedTab = export;
|
||||
editor.IsCompare = false;
|
||||
written += await SaveEditorAsync(window, editor, directory, "edit-remote-export", theme);
|
||||
}
|
||||
|
||||
sample.RunServerRender();
|
||||
await editor.AttachJobsAsync();
|
||||
editor.SelectedTab = editor.Exposure;
|
||||
editor.IsCompare = true;
|
||||
foreach (var theme in Themes)
|
||||
{
|
||||
ThemeManager.Apply(theme);
|
||||
written += await SaveEditorAsync(window, editor, directory, "edit-remote-running", theme);
|
||||
}
|
||||
|
||||
sample.EndServerJobs();
|
||||
await sample.RestrictAccountAsync();
|
||||
await shell.Sequence.OpenAsync(id, reload: true);
|
||||
if (shell.Sequence.Editor is not { IsReadOnly: true } viewer)
|
||||
{
|
||||
Log.Warning("capture", "The server sequence did not open read-only");
|
||||
return written;
|
||||
}
|
||||
DismissToasts(window);
|
||||
viewer.SelectedTab = viewer.Exposure;
|
||||
foreach (var theme in Themes)
|
||||
{
|
||||
ThemeManager.Apply(theme);
|
||||
written += await SaveEditorAsync(window, viewer, directory, "edit-remote-readonly", theme);
|
||||
}
|
||||
return written;
|
||||
}
|
||||
|
||||
private static async Task<int> SaveEditorAsync(Window window, EditorViewModel editor, string directory, string screen, AppTheme theme)
|
||||
{
|
||||
await Settle(window);
|
||||
if (!await editor.WhenIdleAsync(TimeSpan.FromSeconds(30))) Log.Warning("capture", $"{screen} was still busy");
|
||||
return await SaveAsync(window, directory, screen, theme);
|
||||
}
|
||||
|
||||
/// <summary>Toasts of one screen's scene stay out of the next screen's picture.</summary>
|
||||
private static void DismissToasts(MainWindow window)
|
||||
{
|
||||
foreach (var toast in window.Toasts.Toasts.ToList()) window.Toasts.Dismiss(toast);
|
||||
}
|
||||
|
||||
private static async Task<int> SaveAsync(Window window, string directory, string screen, AppTheme theme, ShellViewModel? waitForThumbnails = null)
|
||||
{
|
||||
await Settle(window);
|
||||
if (waitForThumbnails?.Services.Thumbnails is { } thumbnails)
|
||||
{
|
||||
// Thumbnails decode on the thread pool; give them a moment, then settle again.
|
||||
for (var i = 0; i < 40 && thumbnails.PendingLoads > 0; i++) await Task.Delay(50);
|
||||
await Task.Delay(100);
|
||||
await Settle(window);
|
||||
}
|
||||
return Save(window, Path.Combine(directory, $"{screen}-{theme.ToString().ToLowerInvariant()}.png")) ? 1 : 0;
|
||||
}
|
||||
|
||||
private static async Task Settle(Window window)
|
||||
{
|
||||
window.UpdateLayout();
|
||||
// Let bindings, templates, async continuations and deferred renders complete.
|
||||
await window.Dispatcher.InvokeAsync(() => { }, DispatcherPriority.ApplicationIdle);
|
||||
await Task.Delay(30);
|
||||
await window.Dispatcher.InvokeAsync(() => { }, DispatcherPriority.ApplicationIdle);
|
||||
window.UpdateLayout();
|
||||
}
|
||||
|
||||
private static bool Save(Window window, string path)
|
||||
{
|
||||
if (VisualTreeHelper.GetChildrenCount(window) == 0) window.ApplyTemplate();
|
||||
if (VisualTreeHelper.GetChildrenCount(window) == 0)
|
||||
{
|
||||
Log.Warning("capture", "Window has no visual tree; nothing to render");
|
||||
return false;
|
||||
}
|
||||
var root = (FrameworkElement)VisualTreeHelper.GetChild(window, 0);
|
||||
var dpi = VisualTreeHelper.GetDpi(window);
|
||||
var width = (int)Math.Ceiling(root.ActualWidth * dpi.DpiScaleX);
|
||||
var height = (int)Math.Ceiling(root.ActualHeight * dpi.DpiScaleY);
|
||||
if (width <= 0 || height <= 0)
|
||||
{
|
||||
Log.Warning("capture", $"Root element has no size ({root.ActualWidth}×{root.ActualHeight}); skipped {Path.GetFileName(path)}");
|
||||
return false;
|
||||
}
|
||||
var bitmap = new RenderTargetBitmap(width, height, dpi.PixelsPerInchX, dpi.PixelsPerInchY, PixelFormats.Pbgra32);
|
||||
// A right-to-left window's content already renders mirrored, as on screen.
|
||||
bitmap.Render(root);
|
||||
var encoder = new PngBitmapEncoder();
|
||||
encoder.Frames.Add(BitmapFrame.Create(bitmap));
|
||||
using var stream = File.Create(path);
|
||||
encoder.Save(stream);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:s="clr-namespace:Chronos.App.Sections">
|
||||
<!-- Section view model → view. -->
|
||||
<DataTemplate DataType="{x:Type s:LibraryViewModel}"><s:LibraryView /></DataTemplate>
|
||||
<DataTemplate DataType="{x:Type s:ImportViewModel}"><s:ImportView /></DataTemplate>
|
||||
<DataTemplate DataType="{x:Type s:SequenceViewModel}"><s:SequenceView /></DataTemplate>
|
||||
<DataTemplate DataType="{x:Type s:ArchiveViewModel}"><s:ArchiveView /></DataTemplate>
|
||||
<DataTemplate DataType="{x:Type s:JobsViewModel}"><s:JobsView /></DataTemplate>
|
||||
<DataTemplate DataType="{x:Type s:ServerViewModel}"><s:ServerView /></DataTemplate>
|
||||
<DataTemplate DataType="{x:Type s:SettingsViewModel}"><s:SettingsView /></DataTemplate>
|
||||
<DataTemplate DataType="{x:Type s:AboutViewModel}"><s:AboutView /></DataTemplate>
|
||||
</ResourceDictionary>
|
||||
@@ -0,0 +1,78 @@
|
||||
using Chronos.Ui.Controls;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Shell;
|
||||
|
||||
public enum SectionKey
|
||||
{
|
||||
Library,
|
||||
Import,
|
||||
|
||||
/// <summary>One sequence analysed, edited and rendered step by step (owner review 1, R7; formerly Sequence).</summary>
|
||||
Edit,
|
||||
Archive,
|
||||
Jobs,
|
||||
Server,
|
||||
Settings,
|
||||
About,
|
||||
}
|
||||
|
||||
/// <summary>A top-level destination of the navigation rail.</summary>
|
||||
public abstract class SectionViewModel(SectionKey key, string iconKey) : LocalizedViewModel
|
||||
{
|
||||
private bool _isSelected;
|
||||
private int _badge;
|
||||
private bool _inCollapsedRail;
|
||||
|
||||
public SectionKey Key { get; } = key;
|
||||
|
||||
/// <summary>Resource key of the rail icon (e.g. "Icon.Library").</summary>
|
||||
public string IconKey { get; } = iconKey;
|
||||
|
||||
public IconData? Glyph => System.Windows.Application.Current?.TryFindResource(IconKey) as IconData;
|
||||
|
||||
/// <summary>Rail label ("Library").</summary>
|
||||
public string Label => Core.Localization.Loc.L("Shell.Nav." + Key);
|
||||
|
||||
/// <summary>Rail tooltip: what the section is for.</summary>
|
||||
public string ToolTip => Core.Localization.Loc.L("Tooltips.Nav." + Key);
|
||||
|
||||
/// <summary>
|
||||
/// The rail button's tooltip: <see cref="ToolTip"/>, after the section's name while the rail shows icons alone (owner
|
||||
/// review 1).
|
||||
/// </summary>
|
||||
public string RailToolTip => _inCollapsedRail ? Core.Localization.Loc.L("Tooltips.Nav.Collapsed", Label, ToolTip) : ToolTip;
|
||||
|
||||
/// <summary>The rail shows icons alone (<see cref="ShellViewModel.IsRailCollapsed"/>).</summary>
|
||||
internal bool InCollapsedRail
|
||||
{
|
||||
get => _inCollapsedRail;
|
||||
set
|
||||
{
|
||||
if (Set(ref _inCollapsedRail, value)) OnPropertyChanged(nameof(RailToolTip));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Window title suffix ("Chronos — Import").</summary>
|
||||
public virtual string Title => Label;
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
get => _isSelected;
|
||||
set
|
||||
{
|
||||
if (Set(ref _isSelected, value) && value) OnActivated();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Count of items needing attention, shown as a rail badge.</summary>
|
||||
public int Badge
|
||||
{
|
||||
get => _badge;
|
||||
protected set => Set(ref _badge, value);
|
||||
}
|
||||
|
||||
protected virtual void OnActivated()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,363 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Shell;
|
||||
using Chronos.App.Infrastructure;
|
||||
using Chronos.App.Sections;
|
||||
using Chronos.Core.Diagnostics;
|
||||
using Chronos.Core.Localization;
|
||||
using Chronos.Ui.Controls;
|
||||
using Chronos.Ui.Mvvm;
|
||||
|
||||
namespace Chronos.App.Shell;
|
||||
|
||||
/// <summary>State of the main window: rail, current section, job bar, status strip and first run (BRIEF §12.1).</summary>
|
||||
public sealed class ShellViewModel : LocalizedViewModel
|
||||
{
|
||||
private readonly AppSettings _settings;
|
||||
private SectionViewModel _current;
|
||||
private bool _isRailCollapsed;
|
||||
private string? _jobText;
|
||||
private string? _jobName;
|
||||
private double _jobProgress;
|
||||
private bool _jobActive;
|
||||
private bool _jobIndeterminate;
|
||||
private long _sequenceCount;
|
||||
private long _photoCount;
|
||||
private long _totalBytes;
|
||||
private string? _serverName;
|
||||
private int _jobCount;
|
||||
private int _queuedCount;
|
||||
private int _unseenFailures;
|
||||
private WelcomeViewModel? _welcome;
|
||||
private Guid? _currentSequenceId;
|
||||
private int _sequenceRequests;
|
||||
|
||||
public ShellViewModel(AppServices services)
|
||||
{
|
||||
Services = services;
|
||||
_settings = services.Settings;
|
||||
_isRailCollapsed = _settings.RailCollapsed;
|
||||
Library = new LibraryViewModel(this);
|
||||
Import = new ImportViewModel(this);
|
||||
Sequence = new SequenceViewModel(this);
|
||||
Archive = new ArchiveViewModel(this);
|
||||
Jobs = new JobsViewModel(this);
|
||||
Server = new ServerViewModel(this);
|
||||
Settings = new SettingsViewModel(this);
|
||||
About = new AboutViewModel(this);
|
||||
TopSections = [Library, Import, Sequence, Archive, Jobs, Server];
|
||||
BottomSections = [Settings, About];
|
||||
foreach (var section in AllSections) section.InCollapsedRail = _isRailCollapsed;
|
||||
_current = Library;
|
||||
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);
|
||||
// Like the shortcuts above, Ctrl+B leaves the shell behind the first-run dialog alone.
|
||||
ToggleRailCommand = new RelayCommand(() => IsRailCollapsed = !IsRailCollapsed, () => IsShellEnabled);
|
||||
services.Server.PropertyChanged += (_, _) => SetConnection(services.Server.ServerName);
|
||||
if (!_settings.FirstRunCompleted) _welcome = new WelcomeViewModel(this);
|
||||
}
|
||||
|
||||
public AppServices Services { get; }
|
||||
|
||||
public LibraryViewModel Library { get; }
|
||||
public ImportViewModel Import { get; }
|
||||
public SequenceViewModel Sequence { get; }
|
||||
public ArchiveViewModel Archive { get; }
|
||||
public JobsViewModel Jobs { get; }
|
||||
public ServerViewModel Server { get; }
|
||||
public SettingsViewModel Settings { get; }
|
||||
public AboutViewModel About { get; }
|
||||
|
||||
public IReadOnlyList<SectionViewModel> TopSections { get; }
|
||||
public IReadOnlyList<SectionViewModel> BottomSections { get; }
|
||||
public IEnumerable<SectionViewModel> AllSections => TopSections.Concat(BottomSections);
|
||||
|
||||
public ICommand NavigateCommand { get; }
|
||||
public ICommand ToggleRailCommand { get; }
|
||||
|
||||
/// <summary>In-window notifications; the window binds its <see cref="ToastHost"/> here.</summary>
|
||||
public ObservableCollection<Toast> PendingToasts { get; } = [];
|
||||
|
||||
/// <summary>First-run choice (Welcome.html); null once made.</summary>
|
||||
public WelcomeViewModel? Welcome
|
||||
{
|
||||
get => _welcome;
|
||||
private set
|
||||
{
|
||||
if (!Set(ref _welcome, value)) return;
|
||||
OnPropertyChanged(nameof(IsWelcomeOpen));
|
||||
OnPropertyChanged(nameof(IsShellEnabled));
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsWelcomeOpen => _welcome is not null;
|
||||
|
||||
/// <summary>The rail and the sections take input only while no first-run dialog covers them.</summary>
|
||||
public bool IsShellEnabled => _welcome is null;
|
||||
|
||||
public SectionViewModel Current
|
||||
{
|
||||
get => _current;
|
||||
private set
|
||||
{
|
||||
var previous = _current;
|
||||
if (!Set(ref _current, value)) return;
|
||||
previous.PropertyChanged -= OnCurrentChanged;
|
||||
value.PropertyChanged += OnCurrentChanged;
|
||||
OnPropertyChanged(nameof(WindowTitle));
|
||||
OnPropertyChanged(nameof(IsJobBarVisible));
|
||||
}
|
||||
}
|
||||
|
||||
public string WindowTitle => Current == Library ? Loc.L("Shell.AppName") : Loc.L("Shell.WindowTitle", Loc.L("Shell.AppName"), Current.Title);
|
||||
|
||||
/// <summary>The rail shows icons alone (≡ or Ctrl+B); kept at once in the settings (owner review 1).</summary>
|
||||
public bool IsRailCollapsed
|
||||
{
|
||||
get => _isRailCollapsed;
|
||||
set
|
||||
{
|
||||
if (!Set(ref _isRailCollapsed, value)) return;
|
||||
_settings.RailCollapsed = value;
|
||||
foreach (var section in AllSections) section.InCollapsedRail = value;
|
||||
Services.SavePreferences();
|
||||
OnPropertyChanged(nameof(RailToggleToolTip));
|
||||
OnPropertyChanged(nameof(RailToggleName));
|
||||
}
|
||||
}
|
||||
|
||||
public string RailToggleToolTip => Loc.L(IsRailCollapsed ? "Tooltips.Shell.ExpandRail" : "Tooltips.Shell.CollapseRail");
|
||||
|
||||
/// <summary>The rail button's accessible name: two words, the sentence is its tooltip.</summary>
|
||||
public string RailToggleName => Loc.L(IsRailCollapsed ? "Shell.Nav.Expand" : "Shell.Nav.Collapse");
|
||||
|
||||
/// <summary>The sequence the editor opens (set by the Library and the Jobs screen).</summary>
|
||||
public Guid? CurrentSequenceId
|
||||
{
|
||||
get => _currentSequenceId;
|
||||
private set => Set(ref _currentSequenceId, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts <see cref="OpenSequence"/> calls: asking for the open sequence again (the Library, Jobs, a project file) ends a
|
||||
/// choice of another in Edit, while coming back to Edit alone does not (owner review 1, R7).
|
||||
/// </summary>
|
||||
public int SequenceRequests
|
||||
{
|
||||
get => _sequenceRequests;
|
||||
private set => Set(ref _sequenceRequests, value);
|
||||
}
|
||||
|
||||
/// <summary>Loads the data of every screen once the index is open (or failed to open).</summary>
|
||||
public async Task StartAsync()
|
||||
{
|
||||
if (Services.OpenError is { } error) ReportError(error);
|
||||
Jobs.Attach();
|
||||
await Library.AttachAsync();
|
||||
// Edit opened before the index did shows its picker empty until now (neither "no sequences" nor Import).
|
||||
if (Sequence.ShowsPicker && Sequence.IsSelected) _ = Sequence.Picker.ReloadAsync();
|
||||
Settings.Attach();
|
||||
About.Attach();
|
||||
await Server.AttachAsync();
|
||||
}
|
||||
|
||||
/// <summary>Opens a sequence in Edit.</summary>
|
||||
public void OpenSequence(Guid sequenceId)
|
||||
{
|
||||
CurrentSequenceId = sequenceId;
|
||||
SequenceRequests++;
|
||||
Navigate(SectionKey.Edit);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Edit's open sequence (or none) is again the sequence asked for: after Keep editing, a choice cancelled, an open that
|
||||
/// failed, or the sequence asked for deleted. Coming back to Edit then neither asks once more nor tries again; asking
|
||||
/// for a sequence again (<see cref="OpenSequence"/>) does.
|
||||
/// </summary>
|
||||
internal void KeepSequence(Guid? sequenceId) => CurrentSequenceId = sequenceId;
|
||||
|
||||
/// <summary>Closes the first-run overlay for good.</summary>
|
||||
public void CompleteWelcome()
|
||||
{
|
||||
_settings.FirstRunCompleted = true;
|
||||
Services.SaveSettings();
|
||||
Welcome?.Dispose();
|
||||
Welcome = null;
|
||||
}
|
||||
|
||||
/// <summary>Shows the first-run overlay again (capture, tests).</summary>
|
||||
public void ShowWelcome() => Welcome ??= new WelcomeViewModel(this);
|
||||
|
||||
// ---- Job bar ----
|
||||
public string JobText => _jobActive && _jobText is not null
|
||||
? _jobText
|
||||
: _queuedCount > 0 ? Loc.Plural("Shell.JobBar.Ready", _queuedCount) : Loc.L("Shell.JobBar.Idle");
|
||||
|
||||
public double JobProgress { get => _jobProgress; private set => Set(ref _jobProgress, value); }
|
||||
public bool IsJobActive
|
||||
{
|
||||
get => _jobActive;
|
||||
private set
|
||||
{
|
||||
if (Set(ref _jobActive, value)) OnPropertyChanged(nameof(IsJobBarVisible));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The job bar shows "Ready" when idle, except in the editor where it gives its 40 px to the preview (DESIGN §4).</summary>
|
||||
public bool IsJobBarVisible => _jobActive || _current != Sequence;
|
||||
public bool IsJobIndeterminate { get => _jobIndeterminate; private set => Set(ref _jobIndeterminate, value); }
|
||||
|
||||
/// <summary>Pauses the job the bar shows.</summary>
|
||||
public ICommand? StopJobCommand => Jobs.PauseCurrentCommand;
|
||||
|
||||
/// <summary>
|
||||
/// What screen readers hear from the job bar: the job when one starts, the idle line when the last one ends; not its
|
||||
/// progress, speed or time left, which change every second.
|
||||
/// </summary>
|
||||
public string JobAnnouncement => _jobActive && _jobName is not null ? _jobName : JobText;
|
||||
|
||||
/// <summary>
|
||||
/// 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)
|
||||
{
|
||||
_jobText = text;
|
||||
_jobName = text is null ? null : name ?? text;
|
||||
IsJobActive = text is not null;
|
||||
JobProgress = progress;
|
||||
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 ----
|
||||
public string SequencesText => Loc.Plural("Shell.Status.Sequences", _sequenceCount);
|
||||
public string PhotosText => Loc.Plural("Shell.Status.Photos", _photoCount);
|
||||
public string StorageText => _sequenceCount == 0 && _settings.LastArchivePath is null ? Loc.L("Shell.Status.NoArchive") : Formatting.Bytes(_totalBytes);
|
||||
public string ConnectionText => _serverName is null ? Loc.L("Shell.Status.NotConnected") : Loc.L("Shell.Status.Connected", _serverName);
|
||||
public bool IsConnected => _serverName is not null;
|
||||
public string JobsText => Loc.Plural("Shell.Status.Jobs", _jobCount);
|
||||
|
||||
public void SetLibraryTotals(long sequences, long photos, long bytes)
|
||||
{
|
||||
_sequenceCount = sequences;
|
||||
_photoCount = photos;
|
||||
_totalBytes = bytes;
|
||||
OnPropertyChanged(nameof(SequencesText));
|
||||
OnPropertyChanged(nameof(PhotosText));
|
||||
OnPropertyChanged(nameof(StorageText));
|
||||
}
|
||||
|
||||
public void SetConnection(string? serverName)
|
||||
{
|
||||
if (_serverName == serverName) return;
|
||||
_serverName = serverName;
|
||||
OnPropertyChanged(nameof(ConnectionText));
|
||||
OnPropertyChanged(nameof(IsConnected));
|
||||
}
|
||||
|
||||
/// <summary>Active jobs (running + queued) for the status strip, queued ones for the idle job bar.</summary>
|
||||
public void SetJobCount(int active, int queued = 0)
|
||||
{
|
||||
_jobCount = active;
|
||||
_queuedCount = queued;
|
||||
OnPropertyChanged(nameof(JobsText));
|
||||
OnPropertyChanged(nameof(JobText));
|
||||
OnPropertyChanged(nameof(JobAnnouncement));
|
||||
}
|
||||
|
||||
public void Navigate(SectionKey key)
|
||||
{
|
||||
var target = AllSections.First(s => s.Key == key);
|
||||
foreach (var s in AllSections) s.IsSelected = ReferenceEquals(s, target);
|
||||
Current = target;
|
||||
}
|
||||
|
||||
public void ShowToast(Toast toast) => PendingToasts.Add(toast);
|
||||
|
||||
/// <summary>The section on screen renamed itself (the editor opened a sequence): the window title follows.</summary>
|
||||
private void OnCurrentChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName is nameof(SectionViewModel.Title) or "" or null) OnPropertyChanged(nameof(WindowTitle));
|
||||
}
|
||||
|
||||
/// <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,
|
||||
bool runsFromNotification = false) =>
|
||||
ShowToast(new Toast
|
||||
{
|
||||
Title = title,
|
||||
Message = message,
|
||||
ActionText = actionText,
|
||||
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>
|
||||
public void ReportError(Exception ex)
|
||||
{
|
||||
Log.Error("ui", "Operation failed", ex);
|
||||
ShowToast(new Toast
|
||||
{
|
||||
Title = ErrorText.For(ex),
|
||||
IsError = true,
|
||||
ActionText = Loc.L("Common.OpenLogs"),
|
||||
ActionToolTip = Loc.L("Tooltips.Common.OpenLogs"),
|
||||
ActionCommand = new RelayCommand(() => ShellActions.Reveal(Services.Environment.LogDirectory)),
|
||||
});
|
||||
}
|
||||
|
||||
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();
|
||||
Archive.Dispose();
|
||||
Server.Dispose();
|
||||
Settings.Dispose();
|
||||
About.Dispose();
|
||||
Welcome?.Dispose();
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user