Files
Chronos/src/Titano.App/Editor/ExportSync.cs
T
Claude 757695f037 fix(editor): server jobs, stale proxies and read-only accounts in the remote editor
- A server sequence whose cached frames are no longer the server's (a load, a 409
  merge or a frames change event finds other frame ids) turns read-only and says
  why; opening it, or a sequence without cached proxies, queues the proxy
  download and opens it when done. Signed out reads "Connect to the server".
- Server jobs show queued, running (with a bar), paused and analysing glyphs in
  the header with Cancel; a failed or cancelled one raises a toast with Retry.
  Progress alone no longer refreshes the whole editor.
- The server job list is read by state and kind to its last page; "Add to queue"
  sets the job's priority; the event listener survives any failure and always
  releases its frames and connection.
- An account that may render but not edit picks the preset to render without
  changing the project; preset cards and their batch boxes say why they wait.
- Export tab of a server sequence: no local encoder, notices or folder; no Jobs
  history link. Sync at 12 px beside a folder that keeps 96 px and trims.
- Restore's Undo puts back the project from before the restore, only while that
  restore is the editor's last change.
- Export "Sync" of a render that ends while the session is down is queued for the
  saved session's server; skips are logged; sync follows the engine before it
  starts.
- Capture: sequence-remote-export, -running and -readonly, and
  sequence-export-copies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
2026-10-05 22:15:34 +00:00

80 lines
3.7 KiB
C#

using System.IO;
using Titano.Core.Model;
using Titano.Data;
using Titano.Data.Jobs;
using Titano.Data.Processing;
using Titano.Data.Sync;
namespace Titano.App.Editor;
/// <summary>Whether the Export "Sync" option can be used, or why not (its tooltip says which).</summary>
public enum ExportSyncGate
{
Available,
/// <summary>A server sequence: its renders are made on the server and stay there.</summary>
Remote,
/// <summary>No server session is open.</summary>
SignedOut,
/// <summary>The server does not have this sequence.</summary>
NotLinked,
/// <summary>The account may not send files to the server.</summary>
NoUpload,
}
/// <summary>What became of the Export "Sync" of a finished render.</summary>
/// <param name="Gate">Why the render was not sent, or <see cref="ExportSyncGate.Available"/>.</param>
/// <param name="Send">The queued send job; null when it was not queued.</param>
public sealed record ExportSyncResult(ExportSyncGate Gate, Job? Send);
/// <summary>
/// Export "Sync" (Export.html "register the export on the server when connected", BRIEF §14.5): a render made on this
/// PC whose export asked for it is sent to the server the sequence is linked to once it is done
/// (<see cref="SyncService.EnqueueSendExportsAsync"/>). The choice travels inside the render job (its export), so it
/// holds after the editor closes; a render that ends while the session is down is queued for the last session's server
/// and its send waits for the session (and fails visibly on the Jobs screen when it does not come back).
/// </summary>
public sealed class ExportSync(TitanoDatabase db, SyncService sync, JobEngine engine)
{
/// <summary>The option's state for a sequence.</summary>
/// <param name="server">Key of the signed-in server; null while signed out.</param>
/// <param name="linked">The server has the sequence (a sync link joins them).</param>
public static ExportSyncGate Gate(bool isRemote, string? server, bool linked, bool canUpload) =>
isRemote ? ExportSyncGate.Remote
: server is null ? ExportSyncGate.SignedOut
: !linked ? ExportSyncGate.NotLinked
: !canUpload ? ExportSyncGate.NoUpload
: ExportSyncGate.Available;
/// <summary>Queues sending a finished render's output.</summary>
/// <param name="server">Key of the server: the signed-in one, else the one of the saved session; null without either.</param>
/// <param name="canUpload">The account may send files (assumed while the session is down: the server refuses the send otherwise).</param>
/// <returns>The send job or why there is none; null when the job is not a finished render of this PC that asked for it.</returns>
public async Task<ExportSyncResult?> SendAsync(Job job, string? server, bool canUpload, CancellationToken cancellationToken = default)
{
ArgumentNullException.ThrowIfNull(job);
if (job is not { Kind: JobKind.Render, State: JobState.Done, TargetIds: [var target] } || !Wanted(job)) return null;
if (await db.Sequences.GetAsync(target, cancellationToken) is not { } local) return null;
var linked = server is not null && await sync.LinkOfAsync(server, local.Id, cancellationToken) is not null;
var gate = Gate(false, server, linked, canUpload);
return gate == ExportSyncGate.Available
? new ExportSyncResult(gate, await sync.EnqueueSendExportsAsync(engine, server!, local, cancellationToken))
: new ExportSyncResult(gate, null);
}
private static bool Wanted(Job job)
{
try
{
return ProcessingJobs.ReadRender(job.ParametersJson).Export.SyncToServer;
}
catch (InvalidDataException)
{
return false;
}
}
}