feat: wire separate homes into the desktop (owner review 5 P3.2)
The desktop now uses the per-home layout from P3.1: each home keeps its own projects, proxies and originals, and a server is known by its id whichever address reaches it. - Settings keep the known servers (id, name, last address, certificate, aliases, originals archive). Reset and Import keep them; Export leaves them out. - SyncHost records each server the first time it signs in with an id. It names the cache and workspace folders by that id, and re-keys the folders a server had under its addresses at sign-in. The re-key waits while transfer or workspace jobs are pending. - Download originals goes to the server's own archive. It is created beside this PC's archive at the first download, and a toast says where. A sequence that already has a local copy keeps receiving into that copy's archive. A server without an id keeps the 1.0 behaviour. - At start, after the index opens and before any job runs, the folders are sorted into their homes. A toast reports the result: sorted, pending or failed. - The workspace host gives each home's store its own sync. Find, List, usage, clean-up and the trash plan and empty cover every home. Server comparisons go through the identity, so a project stays Online when its server is reached by another address. - The render-node downloads and the server import staging move into the server's folder of the cache. The cache trim keeps `servers`, and the scheduled scan also scans the originals archives. - Settings shows the Home folders rows (Workspace) and the Known servers table (Server). The diagnostics bundle lists the homes. - The dead `AppPaths.CreateDirectories` and `ThumbnailsDirectory` are removed. Refs #66 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4d697a4255
commit
9ad8c6f7a9
44 files changed
+1106
-220
No files matched your search
@@ -12,6 +12,7 @@ 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;
|
||||
@@ -21,6 +22,7 @@ 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;
|
||||
@@ -78,6 +80,8 @@ public sealed class AppServices : IAsyncDisposable
|
||||
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();
|
||||
@@ -151,6 +155,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 +211,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
|
||||
@@ -284,6 +295,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);
|
||||
@@ -474,6 +487,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();
|
||||
@@ -508,6 +581,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.
|
||||
@@ -554,7 +628,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();
|
||||
|
||||
Reference in new issue
Block a user