feat: single setup, mass-pass progress, per-server homes, Desktop shares its library (owner review 5, v1.1.0) (#68)
CI / Build and test (push) Successful in 11m36s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 12s
Release / Build, test and publish (push) Successful in 14m56s
CI / PostgreSQL 16 integration (push) Successful in 10m11s
CI / PostgreSQL 17 integration (push) Successful in 10m15s
CI / Docker image (push) Successful in 45s
Release / Server image (push) Successful in 4m55s

Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
This commit was merged in pull request #68.
This commit is contained in:
Alby96 authored and Alby96 committed 2026-11-15 18:11:43 +01:00
1 parent 988068ee8e
commit 20d64af4a4
793 files changed
+23882 -2096

No files matched your search

+100 -8
View File
@@ -2,7 +2,6 @@ using System.ComponentModel;
using System.IO;
using System.Net.Http;
using System.Reflection;
using Chronos.App.About;
using Chronos.App.Archiving;
using Chronos.App.Import;
using Chronos.App.Jobs;
@@ -13,14 +12,17 @@ using Chronos.App.Workspace;
using Chronos.Core.Archiving;
using Chronos.Core.Diagnostics;
using Chronos.Core.Export;
using Chronos.Core.IO;
using Chronos.Core.Imaging;
using Chronos.Core.Imaging.Decoders;
using Chronos.Core.Model;
using Chronos.Core.Updates;
using Chronos.Core.Video.Managed;
using Chronos.Core.Windows.MediaFoundation;
using Chronos.Core.Windows.Wic;
using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Data.Homes;
using Chronos.Data.Jobs;
using Chronos.Data.Processing;
using Chronos.Data.Scheduling;
@@ -72,12 +74,15 @@ public sealed class AppServices : IAsyncDisposable
// The editor's open and closed groups survive a restart (owner review 1, R3).
Chronos.App.Editor.EditorSettings.Groups.Bind(settings.EditorGroups, saveSettings);
_renderNode = new RenderNodeHost(StartRenderNode);
Share = new LibraryShare(this);
ArchiveSetup = new EngineArchiveSetup(this);
Sync = new SyncHost(this);
ScheduleHost = new DesktopScheduleHost(settings, () => Database, () => Archives);
Workspace = new WorkspaceHost(environment, settings, saveSettings, () => Database, () => Archives, () => Engine);
// A server that keeps projects is the home of the workspace projects of its sequences (owner review 2, R8, phase 5b).
Workspace.ServerHomes = Sync.ProjectHome;
// A server home's folder is named by its server's id, whichever address reached it (owner review 5, #66).
Workspace.Identity = () => Sync.Identity;
Sync.ProjectChanged += Workspace.OnServerProjectChanged;
Server = new ServerSession(settings, saveSettings, new ChronosServerApiFactory(), new DpapiTokenProtector());
Encoders = new MediaFoundationInventory();
@@ -110,6 +115,7 @@ public sealed class AppServices : IAsyncDisposable
{
if (_server is not null) _server.PropertyChanged -= OnServerChanged;
_server = value;
_server.IsOwnLibrary = Share.IsOwn;
_server.PropertyChanged += OnServerChanged;
UpdateRenderNode();
Sync.Update();
@@ -119,6 +125,9 @@ public sealed class AppServices : IAsyncDisposable
/// <summary>Sync with the signed-in server: engine, job connection, background comparison.</summary>
public SyncHost Sync { get; }
/// <summary>Settings › Server › Share this library: this PC's library served to the LAN while Chronos runs (owner review 5, #67).</summary>
public LibraryShare Share { get; }
/// <summary>
/// A job of this PC moved a sequence's folder or changed its title or file names (a Reorganize step), or replaced its
/// frames' files (a conversion), with the sequence's id (any thread): an open editor reads it again where and as it is now.
@@ -151,6 +160,12 @@ public sealed class AppServices : IAsyncDisposable
/// <summary>How the restore staged in Settings › Advanced went when the index opened; null when none was staged.</summary>
public StagedRestoreResult? StagedRestore { get; private set; }
/// <summary>What the sorting of the folders into homes did when the index opened (owner review 5, #66); null when it had nothing to do.</summary>
public HomeLayoutResult? HomeLayout { get; private set; }
/// <summary>Why the folders could not be sorted into homes when the index opened; null when they were, or had nothing to sort.</summary>
public Exception? HomeLayoutError { get; private set; }
/// <summary>Card detection, eject and format (BRIEF §13); started with the index, replaced by a fake in capture.</summary>
public IDeviceMonitor Devices { get; set; } = new WindowsDeviceMonitor();
@@ -201,7 +216,8 @@ public sealed class AppServices : IAsyncDisposable
new(services.Processing?.Options ?? WorkspaceJobOptions.For(archives).Processing,
() => services.Settings.PauseUploadsOnMetered && MeteredNetwork.IsMetered(),
services.Workspace.MovedAsync,
() => services.Workspace.Root);
() => services.Workspace.Root,
services.Workspace.SameServer);
/// <summary>
/// Queues a scan of <paramref name="archive"/> unless one is already waiting or running; the sequences it indexes get
@@ -228,6 +244,7 @@ public sealed class AppServices : IAsyncDisposable
SaveSettingsAction();
UpdateRenderNode();
ApplyJobSettings();
if (!Environment.IsCapture) Share.Apply();
}
/// <summary>Writes the settings file and nothing else: for choices that change only what is shown (the rail, the sequence edited last).</summary>
@@ -284,6 +301,8 @@ public sealed class AppServices : IAsyncDisposable
_schedulerReady.TrySetResult(false);
return;
}
// Before any job runs: the folders of the workspace and the cache go to their homes (owner review 5, #66).
await SortHomesAsync(Database, ct);
try
{
await StartJobsAsync(Database, startEngine: true, ct);
@@ -316,6 +335,8 @@ public sealed class AppServices : IAsyncDisposable
{
await _stopping.CancelAsync().ConfigureAwait(false);
await _schedules.ConfigureAwait(false);
// First: the shared library's clients and its subscriptions to the engine and the scheduler go before they do.
await Share.DisposeAsync().ConfigureAwait(false);
_schedulerReady.TrySetResult(false);
if (Scheduler is not null) await Scheduler.DisposeAsync().ConfigureAwait(false);
_stopping.Dispose();
@@ -348,6 +369,7 @@ public sealed class AppServices : IAsyncDisposable
await StartSchedulerAsync(ct).ConfigureAwait(false);
if (reopen is null)
{
await Share.StartAsync(ct).ConfigureAwait(false);
await ScanNowAsync(started, ct).ConfigureAwait(false);
return;
}
@@ -356,6 +378,7 @@ public sealed class AppServices : IAsyncDisposable
{
if (!string.Equals(reopen, Settings.LastArchivePath, StringComparison.OrdinalIgnoreCase)) return;
if (!await ReopenAsync(reopen, ct).ConfigureAwait(false)) continue;
await Share.StartAsync(ct).ConfigureAwait(false);
await ScanNowAsync(null, ct).ConfigureAwait(false);
Scheduler?.Wake();
return;
@@ -474,6 +497,66 @@ public sealed class AppServices : IAsyncDisposable
}
}
/// <summary>
/// Sorts the workspace's projects and the cache's server folders into their homes (owner review 5, #66:
/// <see cref="HomeLayoutMigration"/>; renames only, a clash to the trash, never deleted), or takes up a sorting a previous
/// start left half done. Projects in use or a workspace being moved wait for a later start; a failure is logged and kept
/// for Settings to tell (<see cref="HomeLayoutError"/>), and the start goes on: the folders not sorted read as before.
/// </summary>
private async Task SortHomesAsync(ChronosDatabase database, CancellationToken ct)
{
try
{
var migration = new HomeLayoutMigration(new HomeLayoutOptions
{
DataDirectory = Environment.DataDirectory,
WorkspaceRoot = Workspace.IsEnabled ? Workspace.Root : null,
CacheRoot = CacheStore.Folder(Environment, Settings),
Identity = Sync.Identity,
CurrentServer = Sync.LastServer,
Database = database,
});
var result = await Task.Run(() => migration.ApplyAsync(ct), ct);
if (result != HomeLayoutResult.Nothing)
{
HomeLayout = result;
Log.Info("app", $"Folders sorted into homes: {result.ProjectsMoved} project(s), {result.EntriesMoved} entr(ies), {result.InUse} in use, "
+ $"{result.Clashes} clash(es){(result.Deferred is { } deferred ? $", the workspace waits ({deferred})" : string.Empty)}");
}
}
catch (Exception ex) when (ex is HomeLayoutException or IOException or UnauthorizedAccessException or InvalidDataException or DatabaseException)
{
HomeLayoutError = ex;
Log.Error("app", "The folders could not be sorted into homes; the next start tries again", ex);
}
finally
{
Workspace.Reopen();
}
}
/// <summary>
/// The scan schedule scanned this PC's archive (any thread): the archives of the servers' downloaded originals are scanned
/// after it (owner review 5, Q1: they are archives of their own, which the schedule, made for one archive, does not name).
/// </summary>
private void OnScheduledScanDone(Job job)
{
if (job is not { Kind: JobKind.Scan, State: JobState.Done, ScheduleId: not null, TargetIds: [var scanned] }) return;
_ = Task.Run(async () =>
{
try
{
var archives = await Sync.OriginalsArchivesAsync(_stopping.Token).ConfigureAwait(false);
if (archives.Any(a => a.Id == scanned)) return;
foreach (var originals in archives) await QueueScanAsync(originals, full: false, _stopping.Token).ConfigureAwait(false);
}
catch (Exception ex) when (ex is DatabaseException or InvalidOperationException or OperationCanceledException)
{
Log.Warning("app", "The archives of the servers' originals could not be queued to be scanned", ex);
}
});
}
private async Task StartJobsAsync(ChronosDatabase database, bool startEngine, CancellationToken ct)
{
_wic = new WicDecoderProvider();
@@ -486,19 +569,24 @@ public sealed class AppServices : IAsyncDisposable
MemoryBudget = () => ProcessingTuning.MemoryBudget(Settings, GC.GetGCMemoryInfo().TotalAvailableMemoryBytes),
// The housekeeping schedule trims the cache to Settings › Storage › Cache limit (owner review 2, R10).
// The workspace-cleanup schedule removes the media past Settings › Workspace's Clean after and Size limit, and reports its trash (phase 5c).
// The shared library's upload-cleanup schedule runs on this PC's scheduler (owner review 5, #67).
CleanupSteps = [new CacheTrimStep(() => CacheStore.Folder(Environment, Settings), () => Settings.CacheLimitGb * (1L << 30)),
new WorkspaceCleanStep(() => Workspace), new WorkspaceTrashStep(() => Workspace)],
new WorkspaceCleanStep(() => Workspace), new WorkspaceTrashStep(() => Workspace), new ShareUploadsStep(() => Share)],
BackupDirectory = Environment.BackupDirectory,
// Told after each step of a Reorganize, and each sequence a conversion replaced or made, while the rest of the job runs.
SequenceChanged = (id, _, _) =>
// While the library is shared, its clients see thumbnails and proxies of what a scan finds, as a server's do.
ImagesAfterScanWhen = () => Share.IsOn,
// Told after each step of a Reorganize, and each sequence a conversion replaced or made, while the rest of the job
// runs; the shared library's clients are told too.
SequenceChanged = (id, change, token) =>
{
SequenceReorganized?.Invoke(id);
return Task.CompletedTask;
return Share.SequenceChangedAsync(id, change, token);
},
ProjectsChanged = (changed, token) => Share.ProjectsChangedAsync(changed, token),
};
Archives = new ArchiveService(database, archive);
// The videos folder may not lie in the workspace either, and a copy of a server's renders downloads through its connection (phase 5).
Archives.Videos.ProtectedFolders = () => [Workspace.Root];
Archives.Videos.ProtectedFolders = () => [Workspace.Root, Share.Folder];
Archives.Videos.Servers = Sync;
Processing = new ProcessingService(database, ProcessingOptions(archive));
Sync.Open(database, Archives, archive);
@@ -508,6 +596,7 @@ public sealed class AppServices : IAsyncDisposable
Engine = new JobEngine(database, handlers, new JobEngineOptions { WorkerId = WorkerId, Kinds = kinds, PriorityQueue = () => PriorityQueue });
// The workspace's size limit runs after each copy of media into it (phase 5c).
Engine.JobChanged += Workspace.OnJobChanged;
Engine.JobChanged += OnScheduledScanDone;
// Sync follows the engine's jobs before it runs any: a render resumed at start that finishes at once is still sent (Export "Sync").
Sync.Update();
// With no handler the engine must not run: an empty kind list would let workers claim (and fail) every job.
@@ -528,6 +617,8 @@ public sealed class AppServices : IAsyncDisposable
AllowsHardware = presetId => AllowsHardware(Settings.HardwareEncoding, presetId),
Host = EncoderHost.Client,
ProducedBy = System.Environment.MachineName,
// A render or an advice recorded on this PC reaches the shared library's clients (owner review 5, #67).
SequenceChanged = (id, change, token) => Share.SequenceChangedAsync(id, change, token),
Tune = basis => ProcessingTuning.Apply(basis, Settings, GC.GetGCMemoryInfo().TotalAvailableMemoryBytes, System.Environment.ProcessorCount,
CacheStore.Folder(Environment, Settings)),
};
@@ -554,7 +645,8 @@ public sealed class AppServices : IAsyncDisposable
var node = new RenderNodeClient(client, processing.Options, new RenderNodeOptions
{
ClientName = System.Environment.MachineName,
CacheDirectory = Path.Combine(cache, "render-node"),
// Each server keeps its own downloads (owner review 5, #66: the render-node folder of its home in the cache).
CacheDirectory = Path.Combine(CacheStore.ServerFolder(cache, Sync.KeyOf(session.Address), Sync.Identity), HomeFolders.RenderNode),
CacheLimitBytes = Settings.CacheLimitGb * (1L << 30),
});
node.Start();