feat: Chronos Desktop shares its library on the LAN (owner review 5 P4)

Chronos Server for Windows is replaced by Settings > Server > Share this
library: Chronos Desktop hosts the server engine in its own process over its
own index, archive and processing services, job engine and scheduler, so a
second PC, the Uploader and render nodes use this PC's library without a
Windows service or a second index.

- Chronos.Server is a library; Chronos.Server.Host is the console exe that
  Docker and development runs start. The App references the library and the
  ASP.NET Core shared framework (no package).
- ServerHost.BuildHosted/HostedServer: reuses the desktop's engines and
  never creates, starts or disposes them; no static log sink, no console
  lifetime; server.json plus desktop-owned values locked "Set in Chronos
  Desktop"; only upload-cleanup and audit-cleanup schedules are added.
- Both modes: by-id endpoints scoped to the served archive, a client's
  render export folder dropped; hosted mode exposes server job kinds only.
- Desktop: LibraryShare (start after the schedules, stop first, port in
  use named), Settings > Server sharing rows, Server > This library panel
  (state, addresses with Copy, ports, fingerprint, temporary admin
  password, clients, admin panel), own library refused by ConnectFlow and
  dropped from LAN discovery, the uploads sweep step, thumbnails after scans
  while sharing, capture scenes server-share and server-share-failed.
- Removed: the Windows service hosting of Chronos.Server, its switches and
  its tests.

Refs #67

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-15 14:55:50 +01:00
1 parent 9ad8c6f7a9
commit 8d41992d84
69 files changed
+2633 -859

No files matched your search

+68 -8
View File
@@ -16,21 +16,24 @@ namespace Chronos.Server.Jobs;
/// running one, in the order of the priority queue of the settings (owner review 1). Render jobs run here only when the registered render
/// handler accepts them (<see cref="ISelectiveJobHandler"/>: managed formats, and MP4 jobs no render node can take);
/// render nodes claim the others (BRIEF §14.5, §14.7). On shutdown running jobs stay marked running and are requeued from their checkpoints at the next start.
/// When Chronos Desktop shares its library (owner review 5, #67) the engine is the desktop's own: this host relays it while the
/// server runs, never starts, stops or disposes it, and the jobs API shows only the kinds a server runs (<see cref="Exposes"/>):
/// the desktop's workspace, sync and download jobs stay its own.
/// </summary>
public sealed class JobEngineHost : IHostedService
{
private static readonly long ProgressInterval = Stopwatch.Frequency / 4;
private readonly ChronosDatabase _db;
private readonly EventHub _events;
private readonly HashSet<JobKind> _kinds;
private readonly Dictionary<Guid, long> _lastProgress = [];
private readonly Lock _gate = new();
private readonly bool _ownsEngine = true;
private int _subscribed;
public JobEngineHost(ChronosDatabase db, IEnumerable<IJobHandler> handlers, IEnumerable<IJobHandlerProvider> providers, ServerOptions options,
EventHub events)
{
_db = db;
_events = events;
// A render handler must be selective: a plain one would take the jobs that need a render node's encoder.
var local = handlers.Concat(providers.SelectMany(p => p.CreateJobHandlers())).Where(h => h.Kind != JobKind.Render || h is ISelectiveJobHandler).ToList();
@@ -42,8 +45,20 @@ public sealed class JobEngineHost : IHostedService
Kinds = _kinds,
PriorityQueue = () => ServerSettingsStore.PriorityQueue(options),
});
Engine.JobChanged += OnJobChanged;
Engine.Progress += OnProgress;
Subscribe();
}
/// <summary>
/// Relays <paramref name="engine"/>, an engine Chronos Desktop runs (owner review 5, #67), from <see cref="StartAsync"/> to
/// <see cref="StopAsync"/>; the engine stays the desktop's.
/// </summary>
public JobEngineHost(JobEngine engine, EventHub events)
{
ArgumentNullException.ThrowIfNull(engine);
_events = events;
_ownsEngine = false;
_kinds = [];
Engine = engine;
}
/// <summary>Node id stamped on jobs this server runs.</summary>
@@ -51,15 +66,60 @@ public sealed class JobEngineHost : IHostedService
public JobEngine Engine { get; }
/// <summary>The engine is the one Chronos Desktop runs, which shares its library (owner review 5, #67).</summary>
public bool Hosted => !_ownsEngine;
/// <summary>True when a job of <paramref name="kind"/> has somewhere to run: a local handler, or render nodes for renders.</summary>
public bool CanRun(JobKind kind) => kind == JobKind.Render || _kinds.Contains(kind);
public bool CanRun(JobKind kind) => kind == JobKind.Render || (_ownsEngine ? _kinds.Contains(kind) : Engine.CanRun(kind) && Exposes(kind));
public Task StartAsync(CancellationToken cancellationToken) => Engine.StartAsync(cancellationToken);
/// <summary>
/// Whether the jobs API lists, shows and acts on jobs of <paramref name="kind"/>: every kind on a server of its own; on a
/// shared desktop library only the kinds a server runs (<see cref="ServerSettingsStore.Kinds"/>), so a client never sees or
/// cancels the desktop's own workspace, sync and download jobs (owner review 5, #67).
/// </summary>
public bool Exposes(JobKind kind) => _ownsEngine || ServerSettingsStore.Kinds.Contains(kind);
public async Task StopAsync(CancellationToken cancellationToken) => await Engine.DisposeAsync();
public Task StartAsync(CancellationToken cancellationToken)
{
if (_ownsEngine) return Engine.StartAsync(cancellationToken);
Subscribe();
return Task.CompletedTask;
}
public async Task StopAsync(CancellationToken cancellationToken)
{
if (_ownsEngine)
{
await Engine.DisposeAsync();
return;
}
// The desktop's engine runs on: only this server stops following it.
if (Interlocked.Exchange(ref _subscribed, 0) == 1)
{
Engine.JobChanged -= OnJobChanged;
Engine.Progress -= OnProgress;
}
}
private void Subscribe()
{
if (Interlocked.Exchange(ref _subscribed, 1) == 1) return;
Engine.JobChanged += OnJobChanged;
Engine.Progress += OnProgress;
}
/// <summary>
/// A job's state changed outside the engine (render nodes, cancellation of node jobs): Chronos Desktop's Jobs section
/// follows these as it follows its engine's own changes while it shares its library (owner review 5, #67).
/// </summary>
public event Action<Job>? ChangedOutside;
/// <summary>Publishes a state change made outside the engine (render nodes, cancellation of node jobs).</summary>
public void Publish(Job job) => OnJobChanged(job);
public void Publish(Job job)
{
OnJobChanged(job);
ChangedOutside?.Invoke(job);
}
private void OnJobChanged(Job job)
{