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:
94 files changed
+10130
-374
No files matched your search
@@ -0,0 +1,136 @@
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using Titano.App.About;
|
||||
using Titano.App.Jobs;
|
||||
using Titano.App.Library;
|
||||
using Titano.App.Server;
|
||||
using Titano.App.Settings;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Data;
|
||||
using Titano.Data.Jobs;
|
||||
|
||||
namespace Titano.App.Infrastructure;
|
||||
|
||||
/// <summary>
|
||||
/// Composition root of local mode (BRIEF §4.4): the SQLite index under the data folder (migrated on open), the one
|
||||
/// <see cref="JobEngine"/> of this PC with the handlers of <see cref="CreateJobHandlers"/>, thumbnails, the server
|
||||
/// session, the encoder inventory, the update check and the archive setup. Started after the window shows, stopped
|
||||
/// when the app exits.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Integration points (one place each):
|
||||
/// <list type="bullet">
|
||||
/// <item><see cref="CreateJobHandlers"/> — register the archive handlers (scan, rebuild, verify, adopt, …) and the
|
||||
/// render handler here.</item>
|
||||
/// <item><see cref="ArchiveSetup"/> — replace <see cref="LocalArchiveSetup"/> with the archive engine's
|
||||
/// implementation (it receives the first-run choices: create a local archive, adopt a folder).</item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
public sealed class AppServices : IAsyncDisposable
|
||||
{
|
||||
private static readonly Lazy<HttpClient> Http = new(() => new HttpClient { Timeout = TimeSpan.FromSeconds(20) });
|
||||
|
||||
public AppServices(AppEnvironment environment, AppSettings settings, Action saveSettings, IAppDialogs dialogs)
|
||||
{
|
||||
Environment = environment;
|
||||
Settings = settings;
|
||||
SaveSettingsAction = saveSettings;
|
||||
Dialogs = dialogs;
|
||||
ArchiveSetup = new LocalArchiveSetup(settings, saveSettings);
|
||||
Server = new ServerSession(settings, saveSettings, new TitanoServerApiFactory(), new DpapiTokenProtector());
|
||||
Encoders = new MediaFoundationInventory();
|
||||
CheckForUpdateAsync = ct => UpdateCheck.FetchAsync(Http.Value, ProductLinks.LatestReleaseApi, VersionText, ct);
|
||||
}
|
||||
|
||||
public AppEnvironment Environment { get; }
|
||||
public AppSettings Settings { get; }
|
||||
public IAppDialogs Dialogs { get; }
|
||||
|
||||
private Action SaveSettingsAction { get; }
|
||||
|
||||
/// <summary>First-run archive actions; replaced by the integrator with the archive engine's implementation.</summary>
|
||||
public IArchiveSetup ArchiveSetup { get; set; }
|
||||
|
||||
public ServerSession Server { get; set; }
|
||||
|
||||
public IEncoderInventory Encoders { get; set; }
|
||||
|
||||
/// <summary>Latest public release (GitHub Releases API of the releases repository, BRIEF §18).</summary>
|
||||
public Func<CancellationToken, Task<ReleaseInfo?>> CheckForUpdateAsync { get; set; }
|
||||
|
||||
/// <summary>The index; null until <see cref="OpenAsync"/> succeeded.</summary>
|
||||
public TitanoDatabase? Database { get; private set; }
|
||||
|
||||
public JobEngine? Engine { get; private set; }
|
||||
|
||||
public IJobQueue? Jobs { get; private set; }
|
||||
|
||||
public ThumbnailService? Thumbnails { get; private set; }
|
||||
|
||||
/// <summary>Why the index could not be opened; null when it is open.</summary>
|
||||
public Exception? OpenError { get; private set; }
|
||||
|
||||
/// <summary>Node id of this PC's workers.</summary>
|
||||
public string WorkerId { get; init; } = System.Environment.MachineName;
|
||||
|
||||
/// <summary>"0.1.0" (informational version).</summary>
|
||||
public static string VersionText { get; } =
|
||||
typeof(AppServices).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "0.0.0";
|
||||
|
||||
/// <summary>
|
||||
/// The job handlers of this PC's engine — the single registration list. The integrator adds the archive
|
||||
/// handlers and the render handler here; a kind without a handler stays queued (it is never claimed here).
|
||||
/// </summary>
|
||||
public static IReadOnlyList<IJobHandler> CreateJobHandlers(AppServices services) =>
|
||||
[
|
||||
];
|
||||
|
||||
public void SaveSettings() => SaveSettingsAction();
|
||||
|
||||
/// <summary>Opens (or creates) the index at <paramref name="databasePath"/>, migrates it and starts the job engine.</summary>
|
||||
public async Task OpenAsync(string databasePath, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
Database = await Task.Run(() => TitanoDatabase.OpenAsync(DatabaseOptions.Sqlite(databasePath), ct), ct);
|
||||
Log.Info("app", $"Index open (schema {Database.SchemaVersion}) at {databasePath}");
|
||||
}
|
||||
catch (Exception ex) when (ex is DatabaseException or System.IO.IOException or UnauthorizedAccessException or DllNotFoundException)
|
||||
{
|
||||
OpenError = ex;
|
||||
Log.Error("app", "The index could not be opened", ex);
|
||||
return;
|
||||
}
|
||||
await StartJobsAsync(Database, startEngine: true, ct);
|
||||
Thumbnails = new ThumbnailService(Database, Settings.ThumbnailMemoryItems);
|
||||
}
|
||||
|
||||
/// <summary>Uses an already open index (capture, tests) instead of opening one; sample data keeps the engine stopped.</summary>
|
||||
public async Task AttachAsync(TitanoDatabase database, bool startEngine = true, CancellationToken ct = default)
|
||||
{
|
||||
Database = database;
|
||||
await StartJobsAsync(database, startEngine, ct);
|
||||
Thumbnails = new ThumbnailService(database, Settings.ThumbnailMemoryItems);
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
(Jobs as IDisposable)?.Dispose();
|
||||
if (Engine is not null) await Engine.DisposeAsync();
|
||||
Thumbnails?.Dispose();
|
||||
Server.Dispose();
|
||||
if (Database is not null) await Database.DisposeAsync();
|
||||
}
|
||||
|
||||
private async Task StartJobsAsync(TitanoDatabase database, bool startEngine, CancellationToken ct)
|
||||
{
|
||||
var handlers = CreateJobHandlers(this);
|
||||
var kinds = handlers.Select(h => h.Kind).Distinct().ToArray();
|
||||
Engine = new JobEngine(database, handlers, new JobEngineOptions { WorkerId = WorkerId, Kinds = kinds });
|
||||
// With no handler the engine must not run: an empty kind list would let workers claim (and fail) every job.
|
||||
var started = startEngine && handlers.Count > 0;
|
||||
if (started) await Engine.StartAsync(ct);
|
||||
Jobs = new EngineJobQueue(database, Engine, started);
|
||||
Log.Info("jobs", started ? $"Job engine started with {Engine.Options.Workers} worker(s) for {string.Join(", ", kinds)}" : "No job handlers registered; jobs stay queued");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user