Files
Leonid PershinandClaude Opus 5 ceacec79e2 Show the collected content: thumbnails and a gallery
Until now a collected image was a row of text, and after a restart it was not
visible at all. The collect list gains a row thumbnail, and a Gallery page
browses the whole store with filters by source, format and address, paged at
120 tiles, with a built-in viewer showing the full size beside its provenance.

Thumbnails decode straight to the width they are drawn at. That is the whole
memory story: a 4000x3000 JPEG is about 48 MB once decoded, so decoding full
size and scaling afterwards runs out of memory long before the user finishes
scrolling. The cache is bounded and owns its bitmaps, which means its capacity
has to comfortably exceed a page - a bitmap evicted while still on screen would
be disposed out from under the renderer.

Paged rather than infinite-scrolled for the same reason: how much to decode is a
decision the page should make, not one the archive's size makes for it.

Video is not previewed and will not be. Extracting a first frame means FFmpeg,
which is a media stack in exchange for one picture per tile; those tiles show a
format badge instead. The refusal happens before touching the disk, because
attempting it would be an exception per tile.

Rendering the page caught the viewer overlay being see-through: it named a brush
that does not exist, and an unresolved DynamicResource fails silently - the
property just keeps its default. That is the second silent-reference bug to
reach a screenshot, so both kinds now have guards: one resolves every
{DynamicResource} in the XAML against both themes, the other checks every
{l:Loc} key exists. Both were confirmed to fail before being kept.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-13 22:55:28 +03:00

73 lines
2.6 KiB
C#

using System.Text.RegularExpressions;
using Avalonia;
using Avalonia.Headless.XUnit;
using Avalonia.Styling;
namespace AvParser.UI.HeadlessTests;
/// <summary>
/// Every resource key the XAML asks for must actually resolve.
/// </summary>
/// <remarks>
/// A <c>DynamicResource</c> naming a key that does not exist fails silently: the property simply
/// keeps its default, so a background never paints and a brush is transparent. That shipped twice —
/// most recently as a viewer overlay you could see straight through, caught only by looking at a
/// screenshot. Both themes are checked, because a key can exist in one dictionary and not the other.
/// </remarks>
public partial class ResourceKeyTests
{
[GeneratedRegex(@"\{(?:Dynamic|Static)Resource\s+([A-Za-z0-9_.]+)\s*\}", RegexOptions.Compiled)]
private static partial Regex ResourceMarkup();
/// <summary>Keys defined inside a view's own <c>Resources</c> block rather than in a theme.</summary>
private static readonly HashSet<string> Local = new(StringComparer.Ordinal) { "LocalizedOptionTemplate" };
private static DirectoryInfo RepositoryRoot()
{
var directory = new DirectoryInfo(AppContext.BaseDirectory);
while (directory is not null && !File.Exists(Path.Combine(directory.FullName, "AvParser.slnx")))
{
directory = directory.Parent;
}
return directory ?? throw new InvalidOperationException("Could not find the repository root.");
}
[AvaloniaTheory]
[InlineData("Light")]
[InlineData("Dark")]
public void Every_resource_key_used_in_xaml_resolves(string theme)
{
var application = Application.Current.ShouldNotBeNull();
application.RequestedThemeVariant = theme == "Light" ? ThemeVariant.Light : ThemeVariant.Dark;
var views = Path.Combine(RepositoryRoot().FullName, "src", "AvParser.UI");
var files = Directory.GetFiles(views, "*.axaml", SearchOption.AllDirectories);
files.ShouldNotBeEmpty();
var missing = new SortedSet<string>(StringComparer.Ordinal);
foreach (var file in files)
{
foreach (Match match in ResourceMarkup().Matches(File.ReadAllText(file)))
{
var key = match.Groups[1].Value;
if (Local.Contains(key))
{
continue;
}
if (!application.TryGetResource(key, application.ActualThemeVariant, out _))
{
missing.Add($"{key} ({Path.GetFileName(file)})");
}
}
}
missing.ShouldBeEmpty();
}
}