From 757695f0372bb41ebc887ed1c9a2cb5f8ade726c Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 5 Oct 2026 22:15:34 +0000 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC --- i18n/en/Editor.resx | 12 +- i18n/en/Tooltips.resx | 11 +- i18n/it/Editor.it.resx | 12 +- i18n/it/Tooltips.it.resx | 11 +- src/Titano.App/DesignTime/SampleData.cs | 87 ++++++- src/Titano.App/Editor/EditorMeasures.xaml | 5 +- src/Titano.App/Editor/EditorPanels.xaml | 23 +- src/Titano.App/Editor/EditorText.cs | 22 +- src/Titano.App/Editor/EditorViewModel.cs | 223 +++++++++++++++--- src/Titano.App/Editor/ExportSync.cs | 29 ++- src/Titano.App/Editor/ExportTab.cs | 116 +++++++-- src/Titano.App/Editor/IRemoteSequenceApi.cs | 11 +- src/Titano.App/Editor/ISequenceSource.cs | 21 +- src/Titano.App/Editor/LocalSequenceSource.cs | 15 ++ src/Titano.App/Editor/RemoteSequenceSource.cs | 149 ++++++++++-- src/Titano.App/Infrastructure/AppServices.cs | 3 +- src/Titano.App/Sections/SequenceView.xaml | 27 ++- src/Titano.App/Sections/SequenceViewModel.cs | 126 ++++++++-- src/Titano.App/Server/RemoteSequenceApi.cs | 26 +- src/Titano.App/Server/SyncHost.cs | 24 +- src/Titano.App/Shell/ScreenCapture.cs | 61 ++++- src/Titano.Data/Sync/SyncService.cs | 3 +- src/Titano.Protocol/Client/TitanoClient.cs | 6 +- .../Titano.App.Tests/Editor/EditorFixture.cs | 30 ++- .../Editor/ExportSyncTests.cs | 12 +- .../Editor/FakeRemoteSequenceApi.cs | 38 ++- .../Editor/RemoteSequenceSourceTests.cs | 2 +- 27 files changed, 932 insertions(+), 173 deletions(-) diff --git a/i18n/en/Editor.resx b/i18n/en/Editor.resx index 31354fcc..007283d1 100644 --- a/i18n/en/Editor.resx +++ b/i18n/en/Editor.resx @@ -50,12 +50,14 @@ Nothing to restore Undo Pick a sequence in the Library + The frames of this sequence changed on the server; get its proxies again.long This sequence is no longer in the archive.long Jobs cannot run until the archive index is open.long The settings of this sequence cannot be read.long Your account cannot change the sequences of this server.long The settings of this sequence were changed elsewhere at the same time.long The saved settings {0} cannot be read.long + Connect to the server to open this sequence.long about {0} Add to queue Batch… @@ -85,7 +87,7 @@ Recommended Render now Resolution - Restore · {0} + Restore settings · {0} Restore copy Result show file @@ -160,6 +162,8 @@ Nothing to change Optimise all Optimise section + Get proxies + Frames changed on {0} Preview 1:1invariant Preview 10 s @@ -177,9 +181,13 @@ This frame cannot be read. Vectors original | corrected + Proxies not received + Getting the proxies Auto Horizon Luminance + {0} · proxies outdated + {0} · read-only Render · {0} Render finished Render queued @@ -191,6 +199,8 @@ Changes not saved Retry Sections + Cancel job + {0} {1} on {2} {0} left f/{0}invariant {0} mminvariant diff --git a/i18n/en/Tooltips.resx b/i18n/en/Tooltips.resx index 10e9d993..facd16b5 100644 --- a/i18n/en/Tooltips.resx +++ b/i18n/en/Tooltips.resx @@ -125,6 +125,7 @@ Rec.709 colour; 10-bit avoids banding in skies, HDR is not offered MP4, AVI, GIF, APNG or a folder of images; the codec list follows Encoder on this PC; Auto prefers hardware + {0} or its render node picks the encoder Where renders go: {0} Renders of a server sequence go to its exports folder on the server Frames per second of the video file @@ -137,7 +138,7 @@ Render with {0}; editing a value makes it Custom Image quality; 95 looks lossless, lower makes smaller files Advisor pick: {0} - Make this PC’s settings kept on {0} the project; Ctrl+Z undoes it + Use this PC’s settings saved on {0} as the project · Ctrl+Z undoes Choose another copy of this PC’s settings, kept when a sync conflict was settled Enter a size between 16 and 16384 pixels After each render on this PC, also send the file to the server; large files take time @@ -179,6 +180,8 @@ Let the advisor set every section from the analysis and list what changed The advisor never stacks on its own: a median erases moving stars Apply the advisor’s heavier choices for this section and list what changed · Ctrl+Z undoes + Frames were added or removed on {0} since the proxies were fetched; get them again to edit or render + Fetch the proxies again and reopen the sequence; the job bar shows the download Pause · Space Play the frames · Space; arrows step one frame Show pixels at 1:1 without interpolation · Ctrl+1; Ctrl+0 fits @@ -195,6 +198,7 @@ Drag the line to compare · drag to pan · wheel zooms · double-click 1:1 Your account can look at this server sequence but not change it Edited with proxies on this PC; changes are saved on {0} and analyses and renders run there + Shown from {0}; your account can look at this sequence but not change it Render with the selected preset; progress in the job bar · Ctrl+R Fix the file name first: {0} Every frame is excluded: include some in the Frames tab @@ -203,10 +207,15 @@ Working out the render; ready in a moment Show the rendered file in Explorer Choose another preset + Choose the preset to render; the project keeps its own Render on {0} with the selected preset; progress beside the title · Ctrl+R Return every control of this section to Auto · Ctrl+Z undoes Try to save now; saving is also retried automatically {0} running on {1} + Cancel the job on {0}; Retry in the notice that follows queues it again from its last checkpoint + {0} paused on {1} + {0} waiting on {1} + Queue the job on {0} again from its last checkpoint Frames combined into each output frame; trails and smoothing grow with it Median and mean remove noise and moving things; star trails keep the brightest pixels Crop, aspect, virtual camera moves diff --git a/i18n/it/Editor.it.resx b/i18n/it/Editor.it.resx index 605ef569..98dd3e02 100644 --- a/i18n/it/Editor.it.resx +++ b/i18n/it/Editor.it.resx @@ -49,12 +49,14 @@ Niente da ripristinare Annulla Scegli una sequenza in Libreria + I fotogrammi di questa sequenza sono cambiati sul server; scarica di nuovo i proxy. Questa sequenza non è più nell’archivio. I lavori non possono partire finché l’indice dell’archivio non è aperto. Le impostazioni di questa sequenza non sono leggibili. Il tuo account non può modificare le sequenze di questo server. Le impostazioni di questa sequenza sono state modificate altrove nello stesso momento. Le impostazioni salvate {0} non si possono leggere. + Connettiti al server per aprire questa sequenza. circa {0} Metti in coda In serie… @@ -80,7 +82,7 @@ Consigliato Renderizza ora Risoluzione - Ripristina · {0} + Ripristina impostazioni · {0} Ripristina copia Risultato mostra file @@ -151,6 +153,8 @@ Niente da cambiare Ottimizza tutto Ottimizza sezione + Scarica i proxy + Fotogrammi cambiati su {0} Anteprima Anteprima 10 s Confronta @@ -167,9 +171,13 @@ Questo fotogramma non si può leggere. Vettori originale | corretto + Proxy non ricevuti + Scaricamento dei proxy Auto Orizzonte Luminanza + {0} · proxy superati + {0} · sola lettura Renderizza · {0} Render completato Render in coda @@ -181,6 +189,8 @@ Modifiche non salvate Riprova Sezioni + Annulla attività + {0} su {2}: {1} mancano {0} Lunghezza Media diff --git a/i18n/it/Tooltips.it.resx b/i18n/it/Tooltips.it.resx index cadd7d70..df776300 100644 --- a/i18n/it/Tooltips.it.resx +++ b/i18n/it/Tooltips.it.resx @@ -125,6 +125,7 @@ Colore Rec.709; 10 bit evitano il banding nel cielo, l’HDR non è disponibile MP4, AVI, GIF, APNG o una cartella di immagini; l’elenco dei codec si adegua Encoder di questo PC; Auto preferisce l’hardware + L’encoder lo sceglie {0} o il suo nodo di rendering Dove vanno i render: {0} I render di una sequenza del server vanno nella sua cartella exports sul server Fotogrammi al secondo del file video @@ -137,7 +138,7 @@ Renderizza con {0}; modificare un valore lo rende Personalizzato Qualità dell’immagine; 95 sembra senza perdite, meno fa file più piccoli Scelta del consulente: {0} - Rende progetto le impostazioni di questo PC conservate il {0}; Ctrl+Z annulla + Usa come progetto le impostazioni di questo PC salvate il {0} · Ctrl+Z annulla Scegli un’altra copia delle impostazioni di questo PC, conservata quando un conflitto di sincronizzazione è stato risolto Inserisci una dimensione tra 16 e 16384 pixel Dopo ogni render su questo PC invia il file anche al server; i file grandi richiedono tempo @@ -179,6 +180,8 @@ Lascia che il consulente imposti ogni sezione dall’analisi ed elenchi cosa è cambiato Il consulente non fa mai stacking da solo: una mediana cancella le stelle in movimento Applica le scelte più incisive del consulente per questa sezione ed elenca cosa è cambiato · Ctrl+Z annulla + Su {0} sono stati aggiunti o tolti fotogrammi dopo lo scaricamento dei proxy; scaricali di nuovo per modificare o renderizzare + Scarica di nuovo i proxy e riapri la sequenza; la barra delle attività mostra lo scaricamento Pausa · Spazio Riproduce i fotogrammi · Spazio; le frecce avanzano di uno Mostra i pixel 1:1 senza interpolazione · Ctrl+1; Ctrl+0 adatta @@ -195,6 +198,7 @@ Trascina la linea per confrontare · trascina per spostare · la rotellina ingrandisce · doppio clic 1:1 Il tuo account può vedere questa sequenza del server ma non modificarla Modificata con i proxy su questo PC; le modifiche si salvano su {0} e analisi e render vengono eseguiti lì + Mostrata da {0}; il tuo account può vedere questa sequenza ma non modificarla Renderizza con il preset scelto; avanzamento nella barra dei lavori · Ctrl+R Correggi prima il nome del file: {0} Tutti i fotogrammi sono esclusi: includine alcuni nella scheda Fotogrammi @@ -203,10 +207,15 @@ Calcolo del render in corso; pronto tra un attimo Mostra il file del render in Esplora file Scegli un altro preset + Scegli il preset da renderizzare; il progetto mantiene il suo Renderizza su {0} con il preset scelto; avanzamento accanto al titolo · Ctrl+R Riporta in Auto ogni controllo di questa sezione · Ctrl+Z annulla Prova a salvare ora; il salvataggio viene anche ritentato da solo {0} in corso su {1} + Annulla l’attività su {0}; Riprova nell’avviso che segue la rimette in coda dall’ultimo punto di ripresa + {0} in pausa su {1} + {0} in attesa su {1} + Rimetti in coda l’attività su {0} dall’ultimo punto di ripresa Fotogrammi combinati in ogni fotogramma d’uscita; scie e levigatura crescono con esso Mediana e media tolgono rumore e ciò che si muove; le scie stellari tengono i pixel più luminosi Ritaglio, formato, movimenti della camera virtuale diff --git a/src/Titano.App/DesignTime/SampleData.cs b/src/Titano.App/DesignTime/SampleData.cs index 7f0e1551..35229609 100644 --- a/src/Titano.App/DesignTime/SampleData.cs +++ b/src/Titano.App/DesignTime/SampleData.cs @@ -45,6 +45,7 @@ public sealed class SampleData private TitanoDatabase? _db; private Guid _sunrise; private Guid _lakeComo; + private Permissions _permissions = RolePermissions.Default(UserRole.Editor); private SampleData(AppServices services) => _services = services; @@ -56,13 +57,13 @@ public sealed class SampleData { if (!services.Environment.IsCapture) throw new InvalidOperationException("Sample data only runs in a capture environment."); var settings = services.Settings; + var sample = new SampleData(services); services.Server.Dispose(); - services.Server = new ServerSession(settings, services.SaveSettings, new SampleServerApiFactory(), new PlainTokenProtector()); + services.Server = new ServerSession(settings, services.SaveSettings, new SampleServerApiFactory(sample), new PlainTokenProtector()); services.Encoders = new SampleEncoders(); services.CheckForUpdateAsync = _ => Task.FromResult(null); services.Devices.Dispose(); services.Devices = new SampleDeviceMonitor(); - var sample = new SampleData(services); services.Sync.RemoteFactory = (_, _, _) => sample._remote; services.Sync.EditorFactory = (_, _, _) => sample._remote; return sample; @@ -163,6 +164,44 @@ public sealed class SampleData for (var i = 0; i < 200 && await db.Jobs.GetAsync(job.Id) is { State: JobState.Queued or JobState.Running }; i++) await Task.Delay(50); } + /// A render of Sunrise over Superga running on the sample server, 43 % done (the remote editor's server job). + public void RunServerRender() => _remote.Run(_sunrise, "render", 1_240, 2_880); + + /// The sample server's jobs end (none waits or runs any more). + public void EndServerJobs() => _remote.EndJobs(); + + /// + /// The signed-in account keeps Read, Upload and Render but loses Edit (server sequences open read-only); the + /// session is read again so the client sees it. + /// + public async Task RestrictAccountAsync() + { + _permissions = Permissions.Read | Permissions.Upload | Permissions.Render; + await _services.Server.RestoreAsync(); + } + + /// + /// The editor's sample as a sequence the sample server also has (so its Export "Sync" applies), with two copies of + /// this PC's settings kept by "Save both" in its .titano folder. + /// + public async Task KeepEditorCopiesAsync(Guid sequenceId) + { + var db = _db ?? throw new InvalidOperationException("FillAsync first."); + var sequence = await db.Sequences.GetAsync(sequenceId) ?? throw new InvalidOperationException("FillEditorAsync first."); + var archive = await db.Archives.GetAsync(sequence.ArchiveId) ?? throw new InvalidOperationException("FillEditorAsync first."); + var meta = new ArchivePaths(archive.RootPath).Sequence(sequence.Folder).MetaDirectory; + Directory.CreateDirectory(meta); + var project = sequence.SettingsJson is { } json ? ProjectSettings.FromJson(json) : new ProjectSettings(); + var copies = new (DateTime Saved, double OffsetEv)[] { (new DateTime(2026, 9, 30, 21, 14, 5), 0.3), (new DateTime(2026, 10, 2, 8, 41, 37), -0.2) }; + foreach (var (saved, offset) in copies) + { + var copy = project with { Exposure = project.Exposure with { ExposureOffsetEv = offset } }; + Titano.Core.IO.AtomicFile.WriteAllText(Path.Combine(meta, SyncService.SavedCopyName(saved)), copy.ToJson()); + } + var remote = _remote.Add(SampleSyncRemote.Dto(sequence), sequence.SettingsJson, sequence.FrameCount); + await _services.Sync.Service!.LinkAsync(ServerAddress, remote, sequence.Id); + } + /// /// The server's side: six sequences this PC also holds (two the same, one with settings changed on both sides, one /// with more originals on the server, one with more here, one with renders this PC lacks) and two only on the server; @@ -582,15 +621,15 @@ public sealed class SampleData } /// A server that always answers as "Studio NAS" with a self-signed certificate the sample trusts. - private sealed class SampleServerApiFactory : IServerApiFactory + private sealed class SampleServerApiFactory(SampleData sample) : IServerApiFactory { - public IServerApi Create(Uri baseAddress, IReadOnlyCollection trustedFingerprints) => new SampleServerApi(baseAddress, trustedFingerprints); + public IServerApi Create(Uri baseAddress, IReadOnlyCollection trustedFingerprints) => new SampleServerApi(sample, baseAddress, trustedFingerprints); } - private sealed class SampleServerApi(Uri baseAddress, IReadOnlyCollection trusted) : IServerApi + /// The sample account, an editor unless took the Edit right away. + private sealed class SampleServerApi(SampleData sample, Uri baseAddress, IReadOnlyCollection trusted) : IServerApi { - private static readonly UserDto User = new(Guid.Empty, "alberto", "Alberto", "editor", (long)RolePermissions.Default(UserRole.Editor), 5_000_000_000_000, - 2_100_000_000_000, false, false, + private UserDto User => new(Guid.Empty, "alberto", "Alberto", "editor", (long)sample._permissions, 5_000_000_000_000, 2_100_000_000_000, false, false, new DateTimeOffset(2025, 1, 1, 0, 0, 0, TimeSpan.Zero), DateTimeOffset.UtcNow); public Uri BaseAddress { get; } = baseAddress; @@ -623,8 +662,8 @@ public sealed class SampleData /// /// The sample server's sequences for the sync table and the editor of a server sequence: listings, manifests /// (frames hashed from their index, so unhashed sample frames match them by count; renders as many as the listing - /// says), settings edits, proxies (generated JPEGs) and jobs the editor posts (kept queued); uploads, originals and - /// analysis reports are not part of the screenshots. + /// says), settings edits, proxies (generated JPEGs) and jobs the editor posts (kept queued until cancelled, or run by + /// ); uploads, originals and analysis reports are not part of the screenshots. /// private sealed class SampleSyncRemote : ISyncRemote, IRemoteSequenceApi { @@ -723,6 +762,20 @@ public sealed class SampleData return Task.FromResult(job); } + /// A job of running for , of frames. + public void Run(Guid sequenceId, string kind, long done, long total) + { + var now = DateTimeOffset.UtcNow; + var job = new JobDto(Guid.CreateVersion7(), kind, [sequenceId], null, "running", "user", done, total, 11.3, (total - done) / 11.3, null, "studio-pc", 1, + null, now.AddMinutes(-2), now.AddMinutes(-2), null); + lock (_jobs) _jobs[job.Id] = job; + } + + public void EndJobs() + { + lock (_jobs) _jobs.Clear(); + } + public Task GetJobAsync(Guid id, CancellationToken cancellationToken) { lock (_jobs) return Task.FromResult(_jobs[id]); @@ -730,7 +783,21 @@ public sealed class SampleData public Task> ListActiveJobsAsync(CancellationToken cancellationToken) { - lock (_jobs) return Task.FromResult>([.. _jobs.Values]); + lock (_jobs) return Task.FromResult>([.. _jobs.Values.Where(j => j.State is "queued" or "running" or "paused")]); + } + + public Task CancelJobAsync(Guid id, CancellationToken cancellationToken) => + Task.FromResult(Update(id, job => job with { State = "cancelled", Finished = DateTimeOffset.UtcNow })); + + public Task RetryJobAsync(Guid id, CancellationToken cancellationToken) => + Task.FromResult(Update(id, job => job with { State = "queued", Error = null, Finished = null })); + + public Task SetJobPriorityAsync(Guid id, string priority, CancellationToken cancellationToken) => + Task.FromResult(Update(id, job => job with { Priority = priority })); + + private JobDto Update(Guid id, Func change) + { + lock (_jobs) return _jobs[id] = change(_jobs[id]); } public void Dispose() diff --git a/src/Titano.App/Editor/EditorMeasures.xaml b/src/Titano.App/Editor/EditorMeasures.xaml index cf5f6426..e158059b 100644 --- a/src/Titano.App/Editor/EditorMeasures.xaml +++ b/src/Titano.App/Editor/EditorMeasures.xaml @@ -228,8 +228,9 @@ +