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

+57 -7
View File
@@ -19,7 +19,10 @@ namespace Chronos.Server.Jobs;
/// retention in force is the audit clean-up schedule's age limit, 0 while it is off or without its audit step:
/// Settings › Logs shows it (<see cref="AuditRetentionAsync"/>) and sets it (<see cref="ApplyAuditRetentionAsync"/>);
/// <see cref="ServerOptions.AuditRetentionDays"/> is only what the schedule is seeded and reset with, or what an environment
/// variable fixes. Every schedule change and run goes out as a <see cref="ScheduleChangedEvent"/>.
/// variable fixes. Every schedule change and run goes out as a <see cref="ScheduleChangedEvent"/>. On the library Chronos
/// Desktop shares (owner review 5, #67) the scheduler is the desktop's, already running: this host follows it while the
/// server runs, adds the server's own system schedules to it (<see cref="ServerScheduleHost.ShareSchedules"/>) and never
/// starts, seeds the desktop's schedules for or disposes it.
/// </summary>
public sealed class SchedulerHost : IHostedService
{
@@ -29,6 +32,10 @@ public sealed class SchedulerHost : IHostedService
private readonly CancellationTokenSource _stopping = new();
private Task _startScan = Task.CompletedTask;
private Task _refresh = Task.CompletedTask;
private readonly bool _ownsScheduler = true;
private readonly Action<ScheduleDto> _changed;
private readonly Action<Guid> _deleted;
private readonly int _auditRetentionDays;
private int _stopped;
public SchedulerHost(ChronosDatabase db, JobEngineHost jobs, ServerScheduleHost host, EventHub events, TimeProvider time, ILogger<SchedulerHost> logger)
@@ -41,8 +48,31 @@ public sealed class SchedulerHost : IHostedService
Host = host;
Scheduler = new Scheduler(db, jobs.Engine, new SchedulerOptions { Time = time });
// The Scheduled tab of the admin panel follows them, the runs that queue no job included.
Scheduler.ScheduleChanged += schedule => events.Publish(new ScheduleChangedEvent(schedule.Id, Deleted: false));
Scheduler.ScheduleDeleted += id => events.Publish(new ScheduleChangedEvent(id, Deleted: true));
_changed = schedule => events.Publish(new ScheduleChangedEvent(schedule.Id, Deleted: false));
_deleted = id => events.Publish(new ScheduleChangedEvent(id, Deleted: true));
Scheduler.ScheduleChanged += _changed;
Scheduler.ScheduleDeleted += _deleted;
}
/// <summary>
/// Follows <paramref name="scheduler"/>, the running scheduler of Chronos Desktop (owner review 5, #67), from
/// <see cref="StartAsync"/> to <see cref="StopAsync"/>.
/// </summary>
public SchedulerHost(ChronosDatabase db, Scheduler scheduler, ServerScheduleHost host, ServerOptions options, EventHub events, TimeProvider time,
ILogger<SchedulerHost> logger)
{
ArgumentNullException.ThrowIfNull(scheduler);
ArgumentNullException.ThrowIfNull(options);
ArgumentNullException.ThrowIfNull(events);
_db = db;
_time = time;
_logger = logger;
_ownsScheduler = false;
_auditRetentionDays = options.AuditRetentionDays;
Host = host;
Scheduler = scheduler;
_changed = schedule => events.Publish(new ScheduleChangedEvent(schedule.Id, Deleted: false));
_deleted = id => events.Publish(new ScheduleChangedEvent(id, Deleted: true));
}
public Scheduler Scheduler { get; }
@@ -51,10 +81,21 @@ public sealed class SchedulerHost : IHostedService
public async Task StartAsync(CancellationToken cancellationToken)
{
var started = Scheduler.Options.Time.GetUtcNow();
await Scheduler.StartAsync(Host, ApplyLockedAgesAsync, cancellationToken);
var stopping = _stopping.Token;
_startScan = Task.Run(() => ScanAtStartAsync(started, stopping), CancellationToken.None);
if (!_ownsScheduler)
{
Scheduler.ScheduleChanged += _changed;
Scheduler.ScheduleDeleted += _deleted;
// The desktop seeds its own system schedules; the server's state brings two more (never overwritten once there).
if (await _db.Schedules.EnsureSystemAsync(ServerScheduleHost.ShareSchedules(_auditRetentionDays), _time.GetUtcNow(), cancellationToken) > 0)
Scheduler.Wake();
}
else
{
var started = Scheduler.Options.Time.GetUtcNow();
await Scheduler.StartAsync(Host, ApplyLockedAgesAsync, cancellationToken);
_startScan = Task.Run(() => ScanAtStartAsync(started, stopping), CancellationToken.None);
}
// Created here, so its first period counts from the start.
var timer = new PeriodicTimer(TimeSpan.FromMinutes(ServerScheduleHost.ScanMinutes), _time);
_refresh = Task.Run(() => RefreshArchiveAsync(timer, stopping), CancellationToken.None);
@@ -66,7 +107,16 @@ public sealed class SchedulerHost : IHostedService
await _stopping.CancelAsync();
await _startScan;
await _refresh;
await Scheduler.DisposeAsync();
if (_ownsScheduler)
{
await Scheduler.DisposeAsync();
}
else
{
// The desktop's scheduler runs on: only this server stops following it.
Scheduler.ScheduleChanged -= _changed;
Scheduler.ScheduleDeleted -= _deleted;
}
_stopping.Dispose();
}