feat(editor): open server sequences with proxies, hero frame to the index, export sync and saved copies

Server sequences that are not in the local index open through a RemoteSequenceSource:
proxies from the cache, project from the server's settings with their version (a 409
merges again), analysis report from the server, analyses and renders posted as server
jobs (one per preset) and followed through the server's events. Set hero now reaches the
index (SequenceEdit.HeroFrameId) so the Library card shows it. The Export tab gains the
Sync option (remembered in the project) and restores "Save both" copies through undo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-03 11:38:11 +00:00
1 parent 90321a7e53
commit 2ff3a6503b
36 files changed
+1307 -116

No files matched your search

+48 -6
View File
@@ -1,8 +1,10 @@
using System.IO;
using Titano.App.Editor;
using Titano.App.Infrastructure;
using Titano.Core.Diagnostics;
using Titano.Core.Model;
using Titano.Data;
using Titano.Data.Jobs;
using Titano.Data.Sync;
using Titano.Protocol.Client;
@@ -14,9 +16,11 @@ public delegate ISyncRemote SyncRemoteFactory(Uri address, string token, IReadOn
/// <summary>
/// This PC's sync with the signed-in server (BRIEF §4.4, §14.5): the <see cref="SyncService"/> of the index, the
/// connection of upload and download jobs (<see cref="ISyncConnector"/>), a <see cref="SyncAgent"/> that keeps the
/// table current while a session is open, started and stopped in order as the session changes, and the
/// <see cref="UploadHold"/> for metered connections. Options come from <see cref="AppSettings.SyncSettingsAutomatically"/>,
/// <see cref="AppSettings.KeepProxiesOffline"/> and <see cref="AppSettings.PauseUploadsOnMetered"/>.
/// table current while a session is open, started and stopped in order as the session changes, the
/// <see cref="UploadHold"/> for metered connections, the connections of editors of server sequences
/// (<see cref="ConnectEditor"/>) and the Export "Sync" of finished renders (<see cref="ExportSync"/>). Options come from
/// <see cref="AppSettings.SyncSettingsAutomatically"/>, <see cref="AppSettings.KeepProxiesOffline"/> and
/// <see cref="AppSettings.PauseUploadsOnMetered"/>.
/// </summary>
public sealed class SyncHost(AppServices services) : ISyncConnector, IAsyncDisposable
{
@@ -26,11 +30,16 @@ public sealed class SyncHost(AppServices services) : ISyncConnector, IAsyncDispo
private Task _switch = Task.CompletedTask;
private Credentials? _credentials;
private (SyncAgent Agent, ISyncRemote Remote, Credentials Credentials)? _running;
private JobEngine? _renders;
/// <summary>Connections over <see cref="TitanoClient"/>; screenshots substitute a fake server.</summary>
public SyncRemoteFactory RemoteFactory { get; set; } = (address, token, trusted) =>
new TitanoSyncRemote(new TitanoClient(address, new CertificatePinning(trusted), $"Titano ({Environment.MachineName})") { Token = token }, ownsClient: true);
/// <summary>Connections of editors of server sequences over <see cref="TitanoClient"/>; screenshots substitute a fake server.</summary>
public RemoteSequenceApiFactory EditorFactory { get; set; } = (address, token, trusted) =>
new TitanoRemoteSequenceApi(new TitanoClient(address, new CertificatePinning(trusted), $"Titano ({Environment.MachineName})") { Token = token });
/// <summary>The engine; null until the index is open.</summary>
public SyncService? Service { get; private set; }
@@ -44,8 +53,10 @@ public sealed class SyncHost(AppServices services) : ISyncConnector, IAsyncDispo
public string? Server => Volatile.Read(ref _credentials) is { } c ? SyncService.ServerKey(c.Address) : null;
/// <summary>The options, and whether the account may change server sequences (without it this PC's edits are not sent).</summary>
public SyncPolicy Policy => new(services.Settings.SyncSettingsAutomatically, services.Settings.KeepProxiesOffline,
services.Server.User is { } user && (user.Permissions & (long)Permissions.Edit) != 0);
public SyncPolicy Policy => new(services.Settings.SyncSettingsAutomatically, services.Settings.KeepProxiesOffline, Allows(Permissions.Edit));
/// <summary>The signed-in account may send files (originals, renders) to the server.</summary>
public bool CanUpload => Allows(Permissions.Upload);
/// <summary>Pauses uploads while the connection is metered and the option is on.</summary>
public UploadHold Uploads { get; } = new(services);
@@ -74,9 +85,17 @@ public sealed class SyncHost(AppServices services) : ISyncConnector, IAsyncDispo
: null;
Volatile.Write(ref _credentials, wanted);
_switch = SwitchAsync(_switch, wanted);
if (services.Engine is { } engine) Uploads.Attach(engine);
if (services.Engine is not { } engine) return;
Uploads.Attach(engine);
if (ReferenceEquals(_renders, engine)) return;
_renders = engine;
engine.JobChanged += OnJobChanged;
}
/// <summary>A connection for the editor of a sequence of the signed-in server; null while signed out.</summary>
public IRemoteSequenceApi? ConnectEditor() =>
Volatile.Read(ref _credentials) is { } c ? EditorFactory(c.Address, c.Token, c.Fingerprints) : null;
/// <summary>Compares now, once the session switch in progress settled; null while signed out.</summary>
public async Task<SyncSnapshot?> RefreshAsync(CancellationToken ct = default)
{
@@ -116,10 +135,33 @@ public sealed class SyncHost(AppServices services) : ISyncConnector, IAsyncDispo
{
Volatile.Write(ref _credentials, null);
Uploads.Dispose();
if (_renders is not null) _renders.JobChanged -= OnJobChanged;
await _switch;
await StopAsync();
}
private bool Allows(Permissions permission) => services.Server.User is { } user && (user.Permissions & (long)permission) != 0;
/// <summary>Export "Sync": a render of this PC that asked for it is sent to the server once done (<see cref="ExportSync"/>).</summary>
private void OnJobChanged(Job job)
{
if (job is not { Kind: JobKind.Render, State: JobState.Done } || Service is not { } service || services.Database is not { } db || _renders is not { } engine)
return;
_ = SendRenderAsync(new ExportSync(db, service, engine), job);
}
private async Task SendRenderAsync(ExportSync exports, Job job)
{
try
{
if (await exports.SendAsync(job, Server, CanUpload) is { } send) Log.Info("sync", $"{job.TargetLabel} will be sent to the server (job {send.Id})");
}
catch (Exception ex) when (ex is Data.DatabaseException or InvalidOperationException)
{
Log.Warning("sync", $"The render {job.TargetLabel} could not be queued for the server", ex);
}
}
private async Task SwitchAsync(Task previous, Credentials? wanted)
{
await previous;