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
This commit is contained in:
Claude committed 2026-10-05 22:15:34 +00:00
1 parent 2813184b85
commit 757695f037
27 files changed
+932 -173

No files matched your search

+112 -14
View File
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System.Net;
using System.Windows.Input;
using System.Windows.Threading;
using Titano.App.Editor;
@@ -9,6 +10,9 @@ using Titano.Core.Export;
using Titano.Core.Imaging.Decoders;
using Titano.Core.Localization;
using Titano.Core.Model;
using Titano.Data.Jobs;
using Titano.Data.Sync;
using Titano.Protocol.Client;
using Titano.Ui.Mvvm;
namespace Titano.App.Sections;
@@ -16,7 +20,8 @@ namespace Titano.App.Sections;
/// <summary>
/// The Sequence section (BRIEF §12.3): opens the sequence the Library, Jobs or the Server screen chose into an
/// <see cref="EditorViewModel"/> (from this PC's archive, or a server sequence with this PC's proxies) and closes the
/// previous one after saving it; without a sequence it shows the empty state. A failed open is reported and leaves the
/// previous one after saving it; without a sequence it shows the empty state. A server sequence whose proxies are
/// missing or out of date fetches them first and opens once they are here. A failed open is reported and leaves the
/// section usable; an edit that cannot be saved is never dropped without the user's confirmation.
/// </summary>
public sealed class SequenceViewModel : SectionViewModel
@@ -26,6 +31,7 @@ public sealed class SequenceViewModel : SectionViewModel
private Guid? _openId;
private bool _isLoading;
private Task _switch = Task.CompletedTask;
private ProxyFetch? _fetch;
public SequenceViewModel(ShellViewModel shell)
: base(SectionKey.Sequence, "Icon.Sequence")
@@ -62,12 +68,36 @@ public sealed class SequenceViewModel : SectionViewModel
public override string Title => _editor?.Title ?? Label;
/// <summary>Opens <paramref name="sequenceId"/> (the editor of another sequence is saved and closed first).</summary>
public Task OpenAsync(Guid sequenceId)
/// <param name="reload">Opens it again even when it is the open one (its proxies were fetched again).</param>
public Task OpenAsync(Guid sequenceId, bool reload = false)
{
_switch = SwitchAsync(_switch, sequenceId);
_switch = SwitchAsync(_switch, sequenceId, reload);
return _switch;
}
/// <summary>
/// Fetches the proxies of server sequence <paramref name="remoteId"/> into this PC's cache (a download job, shown in
/// the job bar and on the Jobs screen) and opens it in the editor once they are here, if it is still the sequence
/// asked for.
/// </summary>
public async Task FetchProxiesAsync(Guid remoteId, string title)
{
var services = Shell.Services;
var sync = services.Sync;
if (sync.Server is not { } server || sync.Service is not { } service) throw new InvalidOperationException(Loc.L("Editor.Error.SignedOut"));
if (services.Engine is not { } engine || services.Database is not { } db) throw new InvalidOperationException(Loc.L("Editor.Error.NoEngine"));
StopFetch();
var fetch = new ProxyFetch(remoteId, title, engine);
fetch.Handler = job => _dispatcher.BeginInvoke(() => OnFetchChanged(fetch, job));
engine.JobChanged += fetch.Handler;
_fetch = fetch;
var job = await service.EnqueueDownloadAsync(engine, server, remoteId, title, SyncDownloadMode.Proxies, null);
fetch.JobId = job.Id;
Shell.Notify(Loc.L("Editor.Proxies.Fetching"), title, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"), () => Shell.Navigate(SectionKey.Jobs));
// A download that ended before its id was known here is handled now.
if (await db.Jobs.GetAsync(job.Id) is { State: JobState.Done or JobState.Failed or JobState.Cancelled } ended) OnFetchChanged(fetch, ended);
}
/// <summary>
/// Stores the open sequence's last edit. When the save fails (archive offline, read-only, busy), asks whether to
/// discard the edit (BRIEF §12.1: modals only for destructive confirmations).
@@ -101,6 +131,7 @@ public sealed class SequenceViewModel : SectionViewModel
public override void Dispose()
{
Shell.PropertyChanged -= OnShellChanged;
StopFetch();
Editor?.Dispose();
base.Dispose();
}
@@ -118,25 +149,64 @@ public sealed class SequenceViewModel : SectionViewModel
/// <summary>
/// Where <paramref name="sequenceId"/> lives: this PC's index, else a sequence of the signed-in server whose proxies
/// this PC keeps (Server screen, "Open with proxies"), edited through the server (BRIEF §14.5), or only shown when the
/// account may not change it.
/// account may not change it. Null when the proxies are not here yet: they are being fetched (<see cref="FetchProxiesAsync"/>).
/// </summary>
private async Task<ISequenceSource> OpenSourceAsync(AppServices services, Guid sequenceId)
private async Task<(ISequenceSource Source, string Title)?> OpenSourceAsync(AppServices services, Guid sequenceId)
{
if (services.Database is not { } db) throw new InvalidOperationException(Loc.L("Editor.Error.NoEngine"));
var processing = services.Processing?.Options;
var decoder = processing?.Archive.Decoder ?? DecoderFactory.CreateClient(null);
if (await db.Sequences.GetAsync(sequenceId) is not null)
if (await db.Sequences.GetAsync(sequenceId) is { } row)
{
var local = new LocalSequenceSource(db, sequenceId, decoder, services.Engine, processing?.Archive);
local.HeroChanged += OnHeroChanged;
return local;
return (local, row.DisplayTitle);
}
var sync = services.Sync;
if (sync.Server is not { } server || sync.Service is not { } service || sync.ConnectEditor() is not { } api)
throw new InvalidOperationException(Loc.L("Editor.Error.SignedOut"));
// The proxy cache's index and files are read off the UI thread.
if (sync.Server is not { } server || sync.Service is not { } service || await Task.Run(() => service.OpenRemote(server, sequenceId)) is not { } remote)
throw new InvalidOperationException(Loc.L("Editor.Error.Missing"));
var api = sync.ConnectEditor() ?? throw new InvalidOperationException(Loc.L("Editor.Error.Missing"));
return new RemoteSequenceSource(remote, api, decoder, readOnly: !sync.Policy.CanEdit);
if (await Task.Run(() => service.OpenRemote(server, sequenceId)) is { } remote)
return (new RemoteSequenceSource(remote, api, decoder, readOnly: !sync.Policy.CanEdit), remote.Sequence.DisplayTitle);
using (api)
{
string title;
try
{
title = (await api.GetSequenceAsync(sequenceId, CancellationToken.None)).DisplayTitle;
}
catch (TitanoApiException ex) when (ex.Status == HttpStatusCode.NotFound)
{
throw new InvalidOperationException(Loc.L("Editor.Error.Missing"), ex);
}
await FetchProxiesAsync(sequenceId, title);
return null;
}
}
/// <summary>The proxy download for an open waiting on it moved: opens the sequence once it is done, says why not when it failed.</summary>
private void OnFetchChanged(ProxyFetch fetch, Job job)
{
if (!ReferenceEquals(fetch, _fetch) || job.Id != fetch.JobId || job.State is not (JobState.Done or JobState.Failed or JobState.Cancelled)) return;
StopFetch();
switch (job.State)
{
// Opened only when it is still the sequence asked for; otherwise the next visit opens it from the cache.
case JobState.Done when Shell.CurrentSequenceId == fetch.RemoteId && IsSelected:
_ = OpenAsync(fetch.RemoteId, reload: true);
break;
case JobState.Failed:
Shell.Notify(Loc.L("Editor.Proxies.Failed"), job.Error ?? fetch.Title, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"),
() => Shell.Navigate(SectionKey.Jobs));
break;
}
}
private void StopFetch()
{
if (_fetch is not { } fetch) return;
_fetch = null;
if (fetch.Handler is { } handler) fetch.Engine.JobChanged -= handler;
}
/// <summary>Set hero changed the frame the Library shows (any thread): its card loads the new thumbnail.</summary>
@@ -158,10 +228,10 @@ public sealed class SequenceViewModel : SectionViewModel
}
}
private async Task SwitchAsync(Task previous, Guid sequenceId)
private async Task SwitchAsync(Task previous, Guid sequenceId, bool reload)
{
await Settled(previous);
if (sequenceId == _openId) return;
if (sequenceId == _openId && !reload) return;
// The open sequence keeps its editor while its last edit is neither stored nor deliberately discarded.
if (!await ConfirmCloseAsync()) return;
var services = Shell.Services;
@@ -175,12 +245,26 @@ public sealed class SequenceViewModel : SectionViewModel
await old.DisposeAsync();
}
_openId = sequenceId;
var source = await OpenSourceAsync(services, sequenceId);
if (await OpenSourceAsync(services, sequenceId) is not { } opened)
{
// The proxies are on their way; the sequence opens when they are here.
_openId = null;
return;
}
var (source, title) = opened;
SequenceContent content;
try
{
content = await source.LoadAsync(CancellationToken.None);
}
catch (ProxiesOutdatedException)
{
// The server's frames are no longer these proxies: fetch them again, then open.
await source.DisposeAsync();
_openId = null;
await FetchProxiesAsync(sequenceId, title);
return;
}
catch
{
await source.DisposeAsync();
@@ -207,4 +291,18 @@ public sealed class SequenceViewModel : SectionViewModel
OnPropertyChanged(nameof(IsEmpty));
}
}
/// <summary>A proxy download an open waits on, with its engine subscription.</summary>
private sealed class ProxyFetch(Guid remoteId, string title, JobEngine engine)
{
public Guid RemoteId { get; } = remoteId;
public string Title { get; } = title;
public JobEngine Engine { get; } = engine;
public Guid JobId { get; set; }
public Action<Job>? Handler { get; set; }
}
}