Files
Chronos/src/Titano.Uploader/Shell/ScreenCapture.cs
T
Claude 1187c36d66 fix(uploader): follow right-to-left languages, name and reach every control by keyboard
Uploader:
- Mirror the main window, the confirmation dialog and the tray menu for ar/he/fa/ur; keep paths, addresses,
  file names, the fingerprint, the brand mark and media glyphs left to right.
- Queue rows take keyboard focus, are named "file · state" for screen readers, and Enter retries a failed
  file; a "✕ n failed" link jumps to the first failure; the list follows the upload near its top.
- Focus moves into the settings panel (Tab cycles inside) and back to the gear, to Browse after sign-in and
  to the refused field after a failed one; activity changes and sign-in errors are announced.
- A wrong address or password marks its field (error border, message in the tooltip); Retry only where it
  can help; session-ended toasts offer Sign in; the form stays visible while its own sign-in runs.
- Watch chips and the add button wrap and shorten long paths; target choices wrap with their fields; the
  settings panel uses the side-panel width with wrapping labels; disabled controls say why.
- The window opens at 760x700 (min 630 high) so the per-file list shows five rows; --capture adds an
  Arabic pass.

Setup:
- Every stage has a default and a cancel button (safe action first), the keyboard moves to the new
  default and outcomes are announced; the title-bar Close is disabled while files are written.
- "Remove my data" measures the user data folder and shows the plan (largest entries, total) before
  Uninstall can run; the tooltip names backups and the uploader queue.
- Folder field before Browse in Tab order; paths and file names left to right; disabled tooltips say why.

Both: byte units come from the language (Common.Size.*).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-03 17:14:54 +00:00

122 lines
4.9 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System.IO;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Titano.Core.Diagnostics;
using Titano.Ui.Theming;
using Titano.Uploader.DesignTime;
namespace Titano.Uploader.Shell;
/// <summary>
/// <c>Titano.Uploader.exe --capture &lt;dir&gt;</c>: renders the window at its default 760×700 — first run (connect),
/// queue running, settings panel — from <see cref="SampleData"/> in the dark and light themes, then once more in
/// Arabic (right to left, dark), and exits.
/// </summary>
public static class ScreenCapture
{
private const double Width = 760;
private const double Height = 700;
/// <param name="directory">Where the PNG files go.</param>
/// <param name="applyLanguage">Switches the UI language (a culture name; null = the OS language).</param>
public static void Run(string directory, Action<string?> applyLanguage)
{
Directory.CreateDirectory(directory);
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, () =>
{
try
{
applyLanguage(null);
CaptureScreens(directory, string.Empty, [AppTheme.Dark, AppTheme.Light]);
// Mirrored layout with paths, addresses and file names kept left to right (BRIEF §16).
applyLanguage("ar");
CaptureScreens(directory, "-ar", [AppTheme.Dark]);
Log.Info("capture", $"Screenshots written to {Path.GetFullPath(directory)}");
}
catch (Exception ex)
{
Log.Error("capture", "Capture failed", ex);
Environment.ExitCode = 1;
}
finally
{
Application.Current.Shutdown();
}
});
}
/// <summary>A fresh window on fresh sample data, so every text is built in the current language.</summary>
private static void CaptureScreens(string directory, string language, IReadOnlyList<AppTheme> themes)
{
var sample = new SampleData();
var vm = sample.CreateViewModel();
var window = new MainWindow(vm, sample.Settings)
{
WindowStartupLocation = WindowStartupLocation.Manual,
Left = -20000,
Top = -20000,
Width = Width,
Height = Height,
ShowActivated = false,
ShowInTaskbar = false,
};
window.Show();
try
{
foreach (var theme in themes)
{
var suffix = language + "-" + theme.ToString().ToLowerInvariant();
ThemeManager.Apply(theme);
sample.ShowConnect();
Save(window, Path.Combine(directory, $"uploader-connect{suffix}.png"));
sample.ShowQueue();
Save(window, Path.Combine(directory, $"uploader-queue{suffix}.png"));
vm.IsSettingsOpen = true;
Save(window, Path.Combine(directory, $"uploader-settings{suffix}.png"));
vm.IsSettingsOpen = false;
}
}
finally
{
window.Close();
vm.Dispose();
}
}
private static void Save(Window window, string path)
{
// Let bindings, templates and deferred layout complete.
window.UpdateLayout();
window.Dispatcher.Invoke(DispatcherPriority.ApplicationIdle, () => { });
window.UpdateLayout();
if (VisualTreeHelper.GetChildrenCount(window) == 0) return;
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) return;
var bitmap = new RenderTargetBitmap(width, height, dpi.PixelsPerInchX, dpi.PixelsPerInchY, PixelFormats.Pbgra32);
bitmap.Render(window.FlowDirection == FlowDirection.RightToLeft ? Mirrored(root) : root);
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bitmap));
using var stream = File.Create(path);
encoder.Save(stream);
}
/// <summary>
/// A right-to-left window is mirrored by a transform on the window itself, which rendering its content alone
/// would leave out (mirrored glyphs, left-to-right layout): draw the content through that mirror.
/// </summary>
private static DrawingVisual Mirrored(FrameworkElement root)
{
var size = new Rect(0, 0, root.ActualWidth, root.ActualHeight);
var visual = new DrawingVisual();
using var dc = visual.RenderOpen();
dc.PushTransform(new MatrixTransform(-1, 0, 0, 1, size.Width, 0));
dc.DrawRectangle(new VisualBrush(root) { Stretch = Stretch.Fill, ViewboxUnits = BrushMappingMode.Absolute, Viewbox = size }, null, size);
return visual;
}
}