feat(app): library, jobs, settings, server, welcome and about screens

Local-mode composition root (SQLite index, one JobEngine fed by a single
handler registration list), keyset-paged library with thumbnail cache and
hover scrub, live job list with throttled updates and the shell job bar,
settings with live template validation and encoder self-test, server
connection with trust-on-first-use and DPAPI token, first-run welcome,
About with update check, and --capture screenshots with synthetic data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 12:26:58 +00:00
1 parent 446daeae2b
commit ffbea7cb74
94 files changed
+10130 -374

No files matched your search

+116
View File
@@ -0,0 +1,116 @@
using System.Collections;
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Titano.App.Settings;
/// <summary>
/// A text setting edited in place (DESIGN §4 inputs): the text box edits <see cref="Text"/>, validated on every
/// keystroke; Enter (or leaving the field) commits a valid value, Esc reverts to the committed one. An invalid value
/// shows the Error border (through <see cref="INotifyDataErrorInfo"/>) and the message in <see cref="ToolTip"/>.
/// </summary>
public sealed class EditableField : INotifyPropertyChanged, INotifyDataErrorInfo
{
private readonly Func<string, string?> _validate;
private readonly Action<string> _commit;
private readonly Func<string> _toolTip;
private string _text;
private string _committed;
private string? _error;
/// <param name="value">The committed value.</param>
/// <param name="validate">Returns the localized problem of a candidate value, or null when it is valid.</param>
/// <param name="commit">Stores a valid, changed value.</param>
/// <param name="toolTip">The tooltip while the value is valid.</param>
public EditableField(string value, Func<string, string?> validate, Action<string> commit, Func<string> toolTip)
{
_text = value;
_committed = value;
_validate = validate;
_commit = commit;
_toolTip = toolTip;
_error = validate(value);
}
public event PropertyChangedEventHandler? PropertyChanged;
public event EventHandler<DataErrorsChangedEventArgs>? ErrorsChanged;
/// <summary>Raised after a value was committed.</summary>
public event EventHandler? Committed;
/// <summary>The text being edited.</summary>
public string Text
{
get => _text;
set
{
value ??= string.Empty;
if (_text == value) return;
_text = value;
OnPropertyChanged();
OnPropertyChanged(nameof(IsDirty));
SetError(_validate(value));
}
}
/// <summary>The value in effect.</summary>
public string Value => _committed;
/// <summary>The problem of the current text; null when valid.</summary>
public string? Error => _error;
public bool HasErrors => _error is not null;
public bool IsDirty => _text != _committed;
/// <summary>The problem while invalid, otherwise the field's own tooltip.</summary>
public string ToolTip => _error ?? _toolTip();
/// <summary>Commits a valid text (Enter); false when the text is invalid.</summary>
public bool Commit()
{
if (_error is not null) return false;
if (!IsDirty) return true;
_committed = _text;
_commit(_committed);
OnPropertyChanged(nameof(Value));
OnPropertyChanged(nameof(IsDirty));
Committed?.Invoke(this, EventArgs.Empty);
return true;
}
/// <summary>Returns the text to the committed value (Esc).</summary>
public void Revert() => Text = _committed;
/// <summary>Replaces the committed value from outside (reset, import, picker) without calling the commit action.</summary>
public void Load(string value)
{
_committed = value ?? string.Empty;
OnPropertyChanged(nameof(Value));
Text = _committed;
OnPropertyChanged(nameof(IsDirty));
SetError(_validate(_text));
}
/// <summary>Re-evaluates the tooltip after a language change.</summary>
public void Refresh()
{
SetError(_validate(_text), force: true);
}
public IEnumerable GetErrors(string? propertyName) =>
_error is not null && (string.IsNullOrEmpty(propertyName) || propertyName == nameof(Text)) ? new[] { _error } : Array.Empty<string>();
private void SetError(string? error, bool force = false)
{
if (_error == error && !force) return;
_error = error;
ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(nameof(Text)));
OnPropertyChanged(nameof(Error));
OnPropertyChanged(nameof(HasErrors));
OnPropertyChanged(nameof(ToolTip));
}
private void OnPropertyChanged([CallerMemberName] string? name = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
+205
View File
@@ -0,0 +1,205 @@
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using Titano.Core.Codecs.Jpeg;
using Titano.Core.Diagnostics;
using Titano.Core.Imaging;
using Titano.Core.Video;
using Titano.Core.Video.Avi;
using Titano.Core.Windows.Dxgi;
using Titano.Core.Windows.MediaFoundation;
namespace Titano.App.Settings;
/// <summary>Who provides an encoder row.</summary>
public enum EncoderSource
{
/// <summary>A Media Foundation MFT (hardware or Microsoft software).</summary>
MediaFoundation,
/// <summary>Titano's managed MJPEG/AVI writer.</summary>
BuiltInMjpeg,
/// <summary>Titano's managed GIF/APNG encoders.</summary>
BuiltInAnimation,
}
/// <summary>One row of Settings › Rendering › Encoders.</summary>
public sealed record EncoderRow(string Codec, string Name, string? Vendor, EncoderSource Source, bool Hardware, bool TenBit, int MaxWidth, int MaxHeight, VideoCodec? VideoCodec)
{
public bool CanSelfTest => Source != EncoderSource.BuiltInAnimation;
/// <summary>"NVIDIA · NVIDIA HEVC Encoder MFT" unless the name already carries the vendor.</summary>
public string DisplayName => Vendor is { } vendor && !Name.Contains(vendor, StringComparison.OrdinalIgnoreCase) ? vendor + " · " + Name : Name;
}
/// <summary>Outcome of encoding the synthetic test clip with one encoder.</summary>
public sealed record SelfTestResult(bool Passed, double FramesPerSecond, string? Error);
/// <summary>Encoders on this PC and their self-test (BRIEF §11.3, §12.8).</summary>
public interface IEncoderInventory
{
/// <summary>"NVIDIA GeForce RTX 4070"; null when no hardware adapter is found.</summary>
string? Adapter();
/// <summary>Enumerates the encoders (slow: call off the UI thread).</summary>
IReadOnlyList<EncoderRow> Detect();
/// <summary>Encodes <see cref="MediaFoundationInventory.TestFrames"/> synthetic frames and reports speed.</summary>
Task<SelfTestResult> SelfTestAsync(EncoderRow row, CancellationToken ct);
}
/// <summary>Media Foundation encoders (in MFTEnumEx merit order) plus Titano's built-in managed encoders.</summary>
public sealed class MediaFoundationInventory : IEncoderInventory
{
public const int TestFrames = 48;
public const int TestWidth = 1280;
public const int TestHeight = 720;
public string? Adapter()
{
try
{
return GpuAdapters.Enumerate().Where(a => !a.IsSoftware).OrderByDescending(a => a.DedicatedVideoMemory).FirstOrDefault()?.Description;
}
catch (Exception ex) when (ex is COMException or DllNotFoundException or EntryPointNotFoundException)
{
Log.Warning("encoders", "Graphics adapters could not be listed", ex);
return null;
}
}
public IReadOnlyList<EncoderRow> Detect()
{
var rows = new List<EncoderRow>();
foreach (var c in new MediaFoundationEncoderProvider().Capabilities)
{
rows.Add(new EncoderRow(CodecName(c.Codec), c.Name, c.Vendor, EncoderSource.MediaFoundation, c.Hardware, c.SupportsTenBit, c.MaxWidth, c.MaxHeight, c.Codec));
}
rows.Add(new EncoderRow("MJPEG · AVI", "Titano", null, EncoderSource.BuiltInMjpeg, false, false, 0, 0, VideoCodec.Mjpeg));
rows.Add(new EncoderRow("GIF · APNG", "Titano", null, EncoderSource.BuiltInAnimation, false, false, 0, 0, null));
return rows;
}
public Task<SelfTestResult> SelfTestAsync(EncoderRow row, CancellationToken ct) => Task.Run(() => SelfTest(row, ct), ct);
public static string CodecName(VideoCodec codec) => codec switch
{
VideoCodec.H264 => "H.264",
VideoCodec.Hevc => "HEVC",
VideoCodec.Av1 => "AV1",
_ => codec.ToString(),
};
private static SelfTestResult SelfTest(EncoderRow row, CancellationToken ct)
{
using var frame = TestPattern(TestWidth, TestHeight);
var clock = Stopwatch.StartNew();
try
{
switch (row.Source)
{
case EncoderSource.MediaFoundation:
EncodeMediaFoundation(row, frame, ct);
break;
case EncoderSource.BuiltInMjpeg:
EncodeMjpeg(frame, ct);
break;
default:
return new SelfTestResult(false, 0, null);
}
clock.Stop();
var fps = TestFrames / Math.Max(clock.Elapsed.TotalSeconds, 1e-3);
Log.Info("encoders", $"Self-test {row.Codec} \"{row.Name}\": {fps:0.#} fps");
return new SelfTestResult(true, fps, null);
}
catch (OperationCanceledException)
{
throw;
}
catch (Exception ex) when (ex is COMException or NotSupportedException or IOException or InvalidOperationException or PlatformNotSupportedException or InvalidDataException)
{
Log.Warning("encoders", $"Self-test {row.Codec} \"{row.Name}\" failed", ex);
return new SelfTestResult(false, 0, ex.Message);
}
}
private static void EncodeMediaFoundation(EncoderRow row, ImageBuffer frame, CancellationToken ct)
{
var path = Path.Combine(Path.GetTempPath(), "titano-selftest-" + Guid.NewGuid().ToString("N") + ".mp4");
try
{
var fps = new Rational(30, 1);
var settings = new EncodeSettings
{
OutputPath = path,
Codec = row.VideoCodec ?? throw new NotSupportedException("No codec"),
Width = TestWidth,
Height = TestHeight,
FrameRate = fps,
BitRate = 8_000_000,
PreferHardware = row.Hardware,
EncoderName = row.Name,
};
using (var session = new MediaFoundationEncoderProvider().Open(settings))
{
for (var i = 0; i < TestFrames; i++)
{
ct.ThrowIfCancellationRequested();
session.WriteFrame(frame, fps.FrameTicks90k);
}
session.Complete();
}
if (!File.Exists(path) || new FileInfo(path).Length == 0) throw new InvalidDataException("The encoder wrote no data.");
}
finally
{
try
{
File.Delete(path);
}
catch (IOException)
{
}
}
}
private static void EncodeMjpeg(ImageBuffer frame, CancellationToken ct)
{
using var output = new MemoryStream();
var writer = new AviMjpegWriter(output, TestWidth, TestHeight, new Rational(30, 1));
var options = new JpegEncodeOptions { Quality = 90 };
for (var i = 0; i < TestFrames; i++)
{
ct.ThrowIfCancellationRequested();
writer.WriteFrame(JpegEncoder.Encode(frame, options));
}
writer.Complete();
if (output.Length == 0) throw new InvalidDataException("The encoder wrote no data.");
}
/// <summary>A smooth colour gradient: compressible, but not trivially so.</summary>
internal static ImageBuffer TestPattern(int width, int height)
{
var image = new ImageBuffer(width, height, 3, clear: false);
for (var c = 0; c < 3; c++)
{
var plane = image.Plane(c);
for (var y = 0; y < height; y++)
{
for (var x = 0; x < width; x++)
{
var u = x / (float)width;
var v = y / (float)height;
plane[y * width + x] = c switch
{
0 => u * 0.8f,
1 => v * 0.6f,
_ => (1 - u) * (1 - v) * 0.7f,
};
}
}
}
return image;
}
}
@@ -0,0 +1,62 @@
using System.Globalization;
using System.Resources;
using Titano.Core.Localization;
namespace Titano.App.Settings;
/// <summary>A language of the language pickers: culture code and its own name ("Italiano").</summary>
public sealed record LanguageOption(string Code, string Name);
/// <summary>
/// The languages this build ships (BRIEF §16): English plus every language of <see cref="Languages.Shipped"/> whose
/// resources are compiled in. Languages announced for later phases appear as soon as their resources exist, and
/// never before (a picker entry that shows English text would mislead).
/// </summary>
public static class LanguageCatalog
{
private static readonly Lazy<IReadOnlyList<LanguageOption>> Detected = new(Detect);
/// <summary>Available languages, English first, then by native name.</summary>
public static IReadOnlyList<LanguageOption> Available => Detected.Value;
/// <summary>True when the satellite resources of <paramref name="code"/> exist.</summary>
public static bool HasResources(string code)
{
if (code.Equals("en", StringComparison.OrdinalIgnoreCase)) return true;
var manager = new ResourceManager("Titano.Core.i18n.Common", typeof(Loc).Assembly);
try
{
return manager.GetResourceSet(CultureInfo.GetCultureInfo(code), createIfNotExists: true, tryParents: false) is not null;
}
catch (MissingManifestResourceException)
{
return false;
}
catch (CultureNotFoundException)
{
return false;
}
}
/// <summary>The option matching <paramref name="culture"/> (or its parent), English when none does.</summary>
public static LanguageOption Match(CultureInfo culture)
{
for (var c = culture; !Equals(c, CultureInfo.InvariantCulture); c = c.Parent)
{
var hit = Available.FirstOrDefault(o => o.Code.Equals(c.Name, StringComparison.OrdinalIgnoreCase));
if (hit is not null) return hit;
}
return Available[0];
}
private static IReadOnlyList<LanguageOption> Detect()
{
var found = Languages.Shipped
.Where(code => !code.Equals("en", StringComparison.OrdinalIgnoreCase) && HasResources(code))
.Select(code => new LanguageOption(code, Languages.NativeName(code)))
.OrderBy(o => o.Name, StringComparer.CurrentCultureIgnoreCase)
.ToList();
found.Insert(0, new LanguageOption("en", Languages.NativeName("en")));
return found;
}
}
+82
View File
@@ -0,0 +1,82 @@
using Titano.Core.Localization;
using Titano.Core.Naming;
namespace Titano.App.Settings;
/// <summary>
/// Live validation and preview of the archive naming templates (BRIEF §7.1): the first problem of a template as one
/// localized sentence, and the first three names a typical import would produce.
/// </summary>
public static class NamingPreview
{
/// <summary>A sample session used for the preview: three frames, two seconds apart, from a Canon EOS R5.</summary>
public static IReadOnlyList<NamingContext> SampleFrames { get; } = BuildSample();
/// <summary>The first problem of <paramref name="template"/>, localized; null when it is valid.</summary>
public static string? Validate(string? template, bool isFolder)
{
var text = template ?? string.Empty;
var parsed = PathTemplate.Parse(text);
if (parsed.Errors.Count > 0)
{
var error = parsed.Errors[0];
return Loc.L("Errors.Template." + error.Code, error.Token ?? string.Empty, error.Position + 1);
}
if (!isFolder && text.Contains('/', StringComparison.Ordinal)) return Loc.L("Errors.Template.FileSeparator");
try
{
foreach (var frame in SampleFrames)
{
var name = isFolder ? parsed.ExpandFolder(frame) : parsed.ExpandFile(frame);
if (name.Length == 0) return Loc.L("Errors.Template.Empty", string.Empty, 1);
}
}
catch (FormatException)
{
return Loc.L("Errors.Template.Format");
}
if (!isFolder && !NumbersFrames(text)) return Loc.L("Errors.Template.NotUnique");
return null;
}
/// <summary>Relative paths of the first three sample frames; empty when either template is invalid.</summary>
public static IReadOnlyList<string> FirstNames(string? folderTemplate, string? fileTemplate)
{
if (Validate(folderTemplate, isFolder: true) is not null || Validate(fileTemplate, isFolder: false) is not null) return [];
var folder = PathTemplate.Parse(folderTemplate!);
var file = PathTemplate.Parse(fileTemplate!);
return SampleFrames.Select(f => Combine(folder.ExpandFolder(f), file.ExpandFile(f))).ToList();
}
private static string Combine(string folder, string file) => folder.Length == 0 ? file : folder + "/" + file;
/// <summary>File names must tell frames apart: a frame number, the time of day or the original name.</summary>
private static bool NumbersFrames(string template)
{
var parsed = PathTemplate.Parse(template);
var names = SampleFrames.Select(parsed.ExpandFile).ToList();
return names.Distinct(StringComparer.OrdinalIgnoreCase).Count() == names.Count;
}
private static List<NamingContext> BuildSample()
{
var start = new DateTime(2026, 9, 28, 18, 2, 11);
return Enumerable.Range(0, 3).Select(i => new NamingContext
{
CapturedAt = start.AddSeconds(2 * i),
SessionStart = start,
Session = 1,
Number = i + 1,
NumberInSession = i + 1,
CameraMake = "Canon",
CameraModel = "Canon EOS R5",
Lens = "RF15-35mm F2.8 L IS USM",
Iso = 100,
ExposureTime = 1.0 / 250,
FNumber = 8,
OriginalName = "IMG_" + (4211 + i).ToString("0000", System.Globalization.CultureInfo.InvariantCulture),
Extension = "CR2",
Title = "Harbour sunset",
}).ToList();
}
}
+120
View File
@@ -0,0 +1,120 @@
using System.Windows.Input;
using Titano.App.Infrastructure;
using Titano.Core.Localization;
using Titano.Ui.Controls;
using Titano.Ui.Mvvm;
namespace Titano.App.Settings;
/// <summary>Sections of the Settings screen (BRIEF §12.8).</summary>
public enum SettingsPage
{
General,
Archive,
Rendering,
Storage,
Server,
Updates,
Advanced,
}
/// <summary>An entry of the section list: name, tooltip (what is inside) and the words the search matches.</summary>
public sealed class SettingsPageItem(SettingsPage page, string[] keywordKeys) : ObservableObject
{
public SettingsPage Page { get; } = page;
public string Label => Loc.L("Settings.Page." + Page);
public string ToolTip => Loc.L("Tooltips.Settings.Page." + Page);
/// <summary>True when <paramref name="text"/> appears in the page name, its tooltip or one of its labels.</summary>
public bool Matches(string text) =>
Label.Contains(text, StringComparison.CurrentCultureIgnoreCase)
|| ToolTip.Contains(text, StringComparison.CurrentCultureIgnoreCase)
|| keywordKeys.Any(k => Loc.L(k).Contains(text, StringComparison.CurrentCultureIgnoreCase));
internal void Refresh() => OnAllPropertiesChanged();
}
/// <summary>A choice of a settings dropdown.</summary>
public sealed record SettingsOption<T>(T Value, string Label)
{
public override string ToString() => Label;
}
/// <summary>One row of the encoder table with its self-test state.</summary>
public sealed class EncoderRowViewModel(EncoderRow row) : ObservableObject
{
private SelfTestResult? _result;
private bool _isTesting;
public EncoderRow Row { get; } = row;
public string Codec => Row.Codec;
/// <summary>"NVIDIA NVENC (hardware)".</summary>
public string Name => Row.Source switch
{
EncoderSource.MediaFoundation => Loc.L(Row.Hardware ? "Settings.Rendering.Encoder.Hardware" : "Settings.Rendering.Encoder.Software", Row.DisplayName),
_ => Loc.L("Settings.Rendering.Encoder.BuiltIn", Row.DisplayName),
};
/// <summary>"Main10", "10-bit" or "—".</summary>
public string TenBitText => !Row.TenBit ? "—" : Row.VideoCodec == Core.Video.VideoCodec.Hevc ? "Main10" : Loc.L("Settings.Rendering.TenBit");
public bool HasTenBit => Row.TenBit;
/// <summary>"8192×8192" or "no limit".</summary>
public string MaxText => Row.MaxWidth > 0 ? $"{Row.MaxWidth}×{Row.MaxHeight}" : Loc.L("Settings.Rendering.NoLimit");
public bool IsTesting
{
get => _isTesting;
set
{
if (Set(ref _isTesting, value)) RaiseResult();
}
}
public SelfTestResult? Result
{
get => _result;
set
{
if (Set(ref _result, value)) RaiseResult();
}
}
public bool HasResult => _result is not null || _isTesting;
public StatusKind ResultKind => _isTesting ? StatusKind.Running : _result is { Passed: true } ? StatusKind.Done : StatusKind.Failed;
/// <summary>"142 fps · ok", "failed", "testing".</summary>
public string ResultText => _isTesting ? Loc.L("Settings.Rendering.Testing")
: _result is not { } r ? "—"
: r.Passed ? Loc.L("Settings.Rendering.Passed", Formatting.Rate(r.FramesPerSecond))
: Loc.L("Settings.Rendering.Failed");
public string ResultToolTip => _result is { Passed: false, Error: { } error } ? error : Loc.L("Tooltips.Settings.SelfTestResult");
internal void Refresh() => OnAllPropertiesChanged();
private void RaiseResult()
{
OnPropertyChanged(nameof(HasResult));
OnPropertyChanged(nameof(ResultKind));
OnPropertyChanged(nameof(ResultText));
OnPropertyChanged(nameof(ResultToolTip));
}
}
/// <summary>A trusted server certificate in Settings › Server.</summary>
public sealed class TrustedCertificateRow(TrustedCertificate certificate, ICommand forget)
{
public TrustedCertificate Certificate { get; } = certificate;
public string Server => Certificate.Server ?? "—";
public string Fingerprint => Titano.App.Server.ServerSession.ShortFingerprint(Certificate.Fingerprint);
public string FullFingerprint => Certificate.Fingerprint;
public string TrustedText => Formatting.Date(Certificate.TrustedAt);
public ICommand ForgetCommand { get; } = forget;
}