diff --git a/i18n/en/Tooltips.resx b/i18n/en/Tooltips.resx index b5b8d98d..10e9d993 100644 --- a/i18n/en/Tooltips.resx +++ b/i18n/en/Tooltips.resx @@ -193,10 +193,12 @@ Show or hide the shot data Overlay the motion to the next frame measured by the engine 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 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 + Your account cannot render on {0} The frame size is unknown: the frames could not be read Working out the render; ready in a moment Show the rendered file in Explorer diff --git a/i18n/it/Tooltips.it.resx b/i18n/it/Tooltips.it.resx index a5fa3c17..cadd7d70 100644 --- a/i18n/it/Tooltips.it.resx +++ b/i18n/it/Tooltips.it.resx @@ -193,10 +193,12 @@ Mostra o nasconde i dati di scatto Sovrappone il movimento verso il fotogramma successivo misurato dal motore 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ì 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 + Il tuo account non può renderizzare su {0} La dimensione dei fotogrammi è sconosciuta: non è stato possibile leggerli Calcolo del render in corso; pronto tra un attimo Mostra il file del render in Esplora file diff --git a/src/Titano.App/Editor/CameraTab.cs b/src/Titano.App/Editor/CameraTab.cs index b346e4ca..a9490c89 100644 --- a/src/Titano.App/Editor/CameraTab.cs +++ b/src/Titano.App/Editor/CameraTab.cs @@ -45,8 +45,8 @@ public sealed class CameraTab : EditorTab new NumberRow(s, "Editor.Camera.OffsetY", "Tooltips.Editor.Camera.OffsetY", -1, 1, 0.05, p => p.Camera.OffsetY, (p, v) => p with { Camera = p.Camera with { OffsetY = v } }, EditorText.Placement), ]; - AddKeyCommand = new RelayCommand(AddKey, () => !Editor.IsBusy && Keys.All(k => k.Frame != Editor.CurrentIndex)); - RemoveKeyCommand = new RelayCommand(RemoveKey, () => !Editor.IsBusy && SelectedKey >= 0); + AddKeyCommand = new RelayCommand(AddKey, () => !Editor.IsLocked && Keys.All(k => k.Frame != Editor.CurrentIndex)); + RemoveKeyCommand = new RelayCommand(RemoveKey, () => !Editor.IsLocked && SelectedKey >= 0); CommitCurveCommand = new RelayCommand(CommitCurve); Refresh(); } @@ -103,13 +103,13 @@ public sealed class CameraTab : EditorTab public ICommand RemoveKeyCommand { get; } /// What Add keyframe does, or why it cannot run now. - public string AddKeyToolTip => Loc.L(Editor.IsBusy ? "Tooltips.Editor.Busy" - : Keys.Any(k => k.Frame == Editor.CurrentIndex) ? "Tooltips.Editor.Camera.KeyExists" : "Tooltips.Editor.Camera.AddKey"); + public string AddKeyToolTip => Editor.LockedToolTip + ?? Loc.L(Keys.Any(k => k.Frame == Editor.CurrentIndex) ? "Tooltips.Editor.Camera.KeyExists" : "Tooltips.Editor.Camera.AddKey"); /// How to edit the keyframe curve, or why it waits. - public string CurveToolTip => Loc.L(Editor.IsBusy ? "Tooltips.Editor.Busy" : "Tooltips.Editor.Camera.Curve"); + public string CurveToolTip => Editor.LockedToolTip ?? Loc.L("Tooltips.Editor.Camera.Curve"); - public string RemoveKeyToolTip => Loc.L(Editor.IsBusy ? "Tooltips.Editor.Busy" : HasSelectedKey ? "Tooltips.Editor.Camera.RemoveKey" : "Tooltips.Editor.Camera.NoKey"); + public string RemoveKeyToolTip => Editor.LockedToolTip ?? Loc.L(HasSelectedKey ? "Tooltips.Editor.Camera.RemoveKey" : "Tooltips.Editor.Camera.NoKey"); /// Run by the curve editor after each finished edit. public ICommand CommitCurveCommand { get; } @@ -248,7 +248,7 @@ public sealed class TimeTab : EditorTab public ICommand CommitCurveCommand { get; } /// How to edit the remap curve, or why it waits. - public string CurveToolTip => Loc.L(Editor.IsBusy ? "Tooltips.Editor.Busy" : "Tooltips.Editor.Time.Curve"); + public string CurveToolTip => Editor.LockedToolTip ?? Loc.L("Tooltips.Editor.Time.Curve"); /// "3,600 frames → 2 min 30 s · 24 fps". public string? PlanText { get => _planText; private set => Set(ref _planText, value); } diff --git a/src/Titano.App/Editor/EditorPanels.xaml b/src/Titano.App/Editor/EditorPanels.xaml index a57e65bf..bebede29 100644 --- a/src/Titano.App/Editor/EditorPanels.xaml +++ b/src/Titano.App/Editor/EditorPanels.xaml @@ -150,7 +150,7 @@ ToolTip="{Binding ResetToolTip}" Visibility="{Binding CanReset, Converter={StaticResource BoolToVisibility}}" /> - + @@ -301,7 +301,7 @@ Visibility="{Binding HasSavedCopies, Converter={StaticResource BoolToVisibility}}" /> - + diff --git a/src/Titano.App/Editor/EditorSession.cs b/src/Titano.App/Editor/EditorSession.cs index 514d3e54..886e2440 100644 --- a/src/Titano.App/Editor/EditorSession.cs +++ b/src/Titano.App/Editor/EditorSession.cs @@ -54,6 +54,9 @@ public sealed class EditorSession : IAsyncDisposable /// A server sequence edited with proxies: saved, analysed and rendered on the server. public bool IsRemote => Source.IsRemote; + /// The project is shown, not changed (): edits, undo and redo do nothing. + public bool IsReadOnly => Source.IsReadOnly; + public SequenceContent Content { get; private set; } public SequenceContext Context { get; private set; } @@ -79,15 +82,15 @@ public sealed class EditorSession : IAsyncDisposable public bool Edit(Func change, string? mergeKey = null) { ArgumentNullException.ThrowIfNull(change); - return History.Apply(change(Project), mergeKey); + return !IsReadOnly && History.Apply(change(Project), mergeKey); } /// The drag or key press behind a run of merged edits ended (). public void EndEditRun() => History.EndRun(); - public bool Undo() => History.Undo(); + public bool Undo() => !IsReadOnly && History.Undo(); - public bool Redo() => History.Redo(); + public bool Redo() => !IsReadOnly && History.Redo(); /// "Optimise section": the advisor's heavier decisions for , one undo step; returns what changed. public IReadOnlyList Optimise(AdvisorSection section) => Optimise([section]); @@ -199,6 +202,7 @@ public sealed class EditorSession : IAsyncDisposable private IReadOnlyList Optimise(IReadOnlyList sections) { + if (IsReadOnly) return []; var settings = Project; var changes = new List(); foreach (var section in sections) diff --git a/src/Titano.App/Editor/EditorTab.cs b/src/Titano.App/Editor/EditorTab.cs index c728295c..a1073c8a 100644 --- a/src/Titano.App/Editor/EditorTab.cs +++ b/src/Titano.App/Editor/EditorTab.cs @@ -16,8 +16,8 @@ public abstract class EditorTab : LocalizedViewModel Editor = editor; Key = key; Section = section; - OptimiseCommand = new RelayCommand(() => Editor.Optimise(Section), () => CanOptimise && !Editor.IsBusy); - ResetCommand = new RelayCommand(() => Editor.Session.ResetSection(Section), () => CanReset && !Editor.IsBusy); + OptimiseCommand = new RelayCommand(() => Editor.Optimise(Section), () => CanOptimise && !Editor.IsLocked); + ResetCommand = new RelayCommand(() => Editor.Session.ResetSection(Section), () => CanReset && !Editor.IsLocked); } public EditorViewModel Editor { get; } @@ -40,9 +40,9 @@ public abstract class EditorTab : LocalizedViewModel public virtual bool CanReset => true; /// What Optimise section does, or why it cannot run now. - public string OptimiseToolTip => Loc.L(!CanOptimise ? "Tooltips.Editor.OptimiseNone" : Editor.IsBusy ? "Tooltips.Editor.Busy" : "Tooltips.Editor.OptimiseSection"); + public string OptimiseToolTip => !CanOptimise ? Loc.L("Tooltips.Editor.OptimiseNone") : Editor.LockedToolTip ?? Loc.L("Tooltips.Editor.OptimiseSection"); - public string ResetToolTip => Loc.L(Editor.IsBusy ? "Tooltips.Editor.Busy" : "Tooltips.Editor.ResetSection"); + public string ResetToolTip => Editor.LockedToolTip ?? Loc.L("Tooltips.Editor.ResetSection"); public ICommand OptimiseCommand { get; } diff --git a/src/Titano.App/Editor/EditorViewModel.cs b/src/Titano.App/Editor/EditorViewModel.cs index 1d03d0f1..31cd5977 100644 --- a/src/Titano.App/Editor/EditorViewModel.cs +++ b/src/Titano.App/Editor/EditorViewModel.cs @@ -86,11 +86,11 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable _player.Tick += (_, _) => Advance(); BackCommand = new RelayCommand(() => Shell.Navigate(SectionKey.Library)); - _analyse = new AsyncRelayCommand(AnalyseAsync, () => !IsBusy && !IsAnalysing); - OptimiseAllCommand = new RelayCommand(OptimiseAll, () => !IsBusy); + _analyse = new AsyncRelayCommand(AnalyseAsync, () => !IsLocked && !IsAnalysing); + OptimiseAllCommand = new RelayCommand(OptimiseAll, () => !IsLocked); _render = new AsyncRelayCommand(() => RenderAsync(JobPriority.User, batch: false), () => CanRender); - UndoCommand = new RelayCommand(() => Session.Undo(), () => !IsBusy && Session.History.CanUndo); - RedoCommand = new RelayCommand(() => Session.Redo(), () => !IsBusy && Session.History.CanRedo); + UndoCommand = new RelayCommand(() => Session.Undo(), () => !IsLocked && Session.History.CanUndo); + RedoCommand = new RelayCommand(() => Session.Redo(), () => !IsLocked && Session.History.CanRedo); PlayCommand = new RelayCommand(() => TogglePlay(limit: 0)); PreviewClipCommand = new RelayCommand(() => TogglePlay(limit: ClipFrames())); StepBackCommand = new RelayCommand(() => CurrentIndex--); @@ -337,17 +337,24 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable /// A deep analysis of this sequence is queued or running (Analyse would queue it twice). public bool IsAnalysing => _jobs.Values.Any(j => j.Kind == JobKind.DeepAnalyse); - public bool IsEditable => !IsBusy; + /// The project is shown, not changed: a server sequence for an account without the Edit right. + public bool IsReadOnly => Session.IsReadOnly; - public string? BusyToolTip => IsBusy ? Loc.L("Tooltips.Editor.Busy") : null; + /// Changes to the project wait (a job runs) or are not allowed (); viewing tools stay live. + public bool IsLocked => IsReadOnly || IsBusy; + + public bool IsEditable => !IsLocked; + + /// Why the controls that change the project are disabled; null while they are not. + public string? LockedToolTip => IsReadOnly ? Loc.L("Tooltips.Editor.ReadOnly") : IsBusy ? Loc.L("Tooltips.Editor.Busy") : null; /// What Analyse does and costs ("about 6 min" from the speed of the last analysis), or why it is disabled. - public string AnalyseToolTip => IsBusy ? Loc.L("Tooltips.Editor.Busy") - : IsAnalysing ? Loc.L("Tooltips.Editor.AnalyseQueued") + public string AnalyseToolTip => LockedToolTip + ?? (IsAnalysing ? Loc.L("Tooltips.Editor.AnalyseQueued") : _analysisSecondsPerFrame is { } perFrame ? Loc.L("Tooltips.Editor.AnalyseCost", Formatting.Duration(TimeSpan.FromSeconds(perFrame * FrameCount))) - : Loc.L("Tooltips.Editor.Analyse"); + : Loc.L("Tooltips.Editor.Analyse")); - public string OptimiseAllToolTip => Loc.L(IsBusy ? "Tooltips.Editor.Busy" : "Tooltips.Editor.OptimiseAll"); + public string OptimiseAllToolTip => LockedToolTip ?? Loc.L("Tooltips.Editor.OptimiseAll"); public bool IsPlaying => _player.IsEnabled; @@ -384,6 +391,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable /// Why the project's export cannot be rendered now, localised; null when it can. public string? RenderBlockedReason => Plan switch { + _ when IsRemote && !Shell.Services.Sync.CanRender => Loc.L("Tooltips.Editor.Render.NoRight", RemoteText ?? string.Empty), null when _planned => Loc.L("Tooltips.Editor.Render.NoSource"), null => Loc.L("Tooltips.Editor.Render.Planning"), { NameError: { } error } => Loc.L("Tooltips.Editor.Render.NameError", error), @@ -865,8 +873,9 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable { OnPropertyChanged(nameof(IsBusy)); OnPropertyChanged(nameof(IsAnalysing)); + OnPropertyChanged(nameof(IsLocked)); OnPropertyChanged(nameof(IsEditable)); - OnPropertyChanged(nameof(BusyToolTip)); + OnPropertyChanged(nameof(LockedToolTip)); OnPropertyChanged(nameof(AnalyseToolTip)); OnPropertyChanged(nameof(OptimiseAllToolTip)); OnPropertyChanged(nameof(ServerJobText)); diff --git a/src/Titano.App/Editor/ExportTab.cs b/src/Titano.App/Editor/ExportTab.cs index 122c8a04..75570d70 100644 --- a/src/Titano.App/Editor/ExportTab.cs +++ b/src/Titano.App/Editor/ExportTab.cs @@ -119,13 +119,13 @@ public sealed class ExportTab : EditorTab public ExportTab(EditorViewModel editor) : base(editor, "Export", AdvisorSection.Export) { - SelectCommand = new RelayCommand(p => Select(p as PresetCard), _ => !Editor.IsBusy); + SelectCommand = new RelayCommand(p => Select(p as PresetCard), _ => !Editor.IsLocked); _renderNow = new AsyncRelayCommand(() => Editor.RenderAsync(JobPriority.User, batch: false), () => Editor.CanRender); _addToQueue = new AsyncRelayCommand(() => Editor.RenderAsync(JobPriority.Normal, batch: false), () => Editor.CanRender); _batch = new AsyncRelayCommand(() => Editor.RenderAsync(JobPriority.User, batch: true), () => Editor.CanRender && Batch.Count > 0); HistoryCommand = new RelayCommand(OpenHistory); RevealLastCommand = new RelayCommand(() => ShellActions.Reveal(Editor.Session.Content.Renders[0].OutputPath), () => CanReveal); - _restore = new AsyncRelayCommand(RestoreAsync, () => !Editor.IsBusy && SelectedCopy is not null); + _restore = new AsyncRelayCommand(RestoreAsync, () => !Editor.IsLocked && SelectedCopy is not null); ResetFrameRateCommand = new RelayCommand(() => EditOverrides(o => o with { FrameRate = null })); Width = new EditableField(string.Empty, ValidateSize, v => EditOverrides(o => o with { Width = ParseSize(v) }), () => Loc.L("Tooltips.Editor.Export.Width")); Height = new EditableField(string.Empty, ValidateSize, v => EditOverrides(o => o with { Height = ParseSize(v) }), () => Loc.L("Tooltips.Editor.Export.Height")); @@ -211,7 +211,7 @@ public sealed class ExportTab : EditorTab /// "Restore · 03/10/2026 14:22". public string RestoreText => Loc.L("Editor.Export.Restore", SelectedCopy?.Label ?? string.Empty); - public string RestoreToolTip => Editor.IsBusy ? Loc.L("Tooltips.Editor.Busy") : Loc.L("Tooltips.Editor.Export.Restore", SelectedCopy?.Label ?? string.Empty); + public string RestoreToolTip => Editor.LockedToolTip ?? Loc.L("Tooltips.Editor.Export.Restore", SelectedCopy?.Label ?? string.Empty); public ICommand RestoreCommand => _restore; diff --git a/src/Titano.App/Editor/FramesTab.cs b/src/Titano.App/Editor/FramesTab.cs index 9d2cce79..a2025776 100644 --- a/src/Titano.App/Editor/FramesTab.cs +++ b/src/Titano.App/Editor/FramesTab.cs @@ -89,7 +89,7 @@ public sealed class FrameRow(FramesTab owner, Frame frame, int index) : Observab public string ExcludeText => Loc.L(IsExcluded ? "Editor.Frames.Include" : "Editor.Frames.Exclude"); - public string ExcludeToolTip => Loc.L(owner.Editor.IsBusy ? "Tooltips.Editor.Busy" : IsExcluded ? "Tooltips.Editor.Frames.Include" : "Tooltips.Editor.Frames.Exclude"); + public string ExcludeToolTip => owner.Editor.LockedToolTip ?? Loc.L(IsExcluded ? "Tooltips.Editor.Frames.Include" : "Tooltips.Editor.Frames.Exclude"); /// A job of the sequence started or ended: the action tooltips say why they wait. public void RefreshBusy() => OnPropertyChanged(nameof(ExcludeToolTip)); @@ -125,8 +125,8 @@ public sealed class FramesTab : EditorTab public FramesTab(EditorViewModel editor) : base(editor, "Frames", AdvisorSection.Frames) { - ToggleExcludeCommand = new RelayCommand(p => ToggleExcluded(p is FrameRow row ? row.Index : Editor.CurrentIndex), _ => !Editor.IsBusy); - SetHeroCommand = new RelayCommand(p => Editor.Session.SetHero(p is FrameRow row ? row.Index : Editor.CurrentIndex), _ => !Editor.IsBusy); + ToggleExcludeCommand = new RelayCommand(p => ToggleExcluded(p is FrameRow row ? row.Index : Editor.CurrentIndex), _ => !Editor.IsLocked); + SetHeroCommand = new RelayCommand(p => Editor.Session.SetHero(p is FrameRow row ? row.Index : Editor.CurrentIndex), _ => !Editor.IsLocked); SeekCommand = new RelayCommand(p => { if (p is FindingItem { Frame: { } frame }) Editor.CurrentIndex = frame; @@ -179,10 +179,10 @@ public sealed class FramesTab : EditorTab public string CurrentExcludeText => Loc.L(IsCurrentExcluded ? "Editor.Frames.IncludeFrame" : "Editor.Frames.ExcludeFrame"); - public string CurrentExcludeToolTip => Loc.L(Editor.IsBusy ? "Tooltips.Editor.Busy" : IsCurrentExcluded ? "Tooltips.Editor.Frames.Include" : "Tooltips.Editor.Frames.Exclude"); + public string CurrentExcludeToolTip => Editor.LockedToolTip ?? Loc.L(IsCurrentExcluded ? "Tooltips.Editor.Frames.Include" : "Tooltips.Editor.Frames.Exclude"); /// What Set hero does, or why it waits. - public string HeroToolTip => Loc.L(Editor.IsBusy ? "Tooltips.Editor.Busy" : "Tooltips.Editor.Frames.Hero"); + public string HeroToolTip => Editor.LockedToolTip ?? Loc.L("Tooltips.Editor.Frames.Hero"); public override bool CanReset => false; diff --git a/src/Titano.App/Editor/ISequenceSource.cs b/src/Titano.App/Editor/ISequenceSource.cs index 4ffde1b5..083a3bd2 100644 --- a/src/Titano.App/Editor/ISequenceSource.cs +++ b/src/Titano.App/Editor/ISequenceSource.cs @@ -20,6 +20,12 @@ public interface ISequenceSource : IAsyncDisposable /// bool IsRemote { get; } + /// + /// The project is shown, not changed (a server sequence for an account without the Edit right): the editor + /// disables every change and the source refuses to store one. + /// + bool IsReadOnly { get; } + /// A job that may concern the sequence changed (any thread): this PC's engine, or the server's events. event Action? JobChanged; diff --git a/src/Titano.App/Editor/LocalSequenceSource.cs b/src/Titano.App/Editor/LocalSequenceSource.cs index 0de57ef6..c9b429c1 100644 --- a/src/Titano.App/Editor/LocalSequenceSource.cs +++ b/src/Titano.App/Editor/LocalSequenceSource.cs @@ -53,6 +53,8 @@ public sealed class LocalSequenceSource : ISequenceSource public bool IsRemote => false; + public bool IsReadOnly => false; + public event Action? JobChanged; /// A save changed the frame the Library shows for the sequence: the stored row (any thread). diff --git a/src/Titano.App/Editor/RemoteSequenceSource.cs b/src/Titano.App/Editor/RemoteSequenceSource.cs index b856f5ce..4a151dd5 100644 --- a/src/Titano.App/Editor/RemoteSequenceSource.cs +++ b/src/Titano.App/Editor/RemoteSequenceSource.cs @@ -46,13 +46,15 @@ public sealed class RemoteSequenceSource : ISequenceSource private int _version; private int _disposed; - public RemoteSequenceSource(RemoteSequence remote, IRemoteSequenceApi api, ImageDecoder decoder) + /// The account may look at the sequence but not change it (no Edit right on the server). + public RemoteSequenceSource(RemoteSequence remote, IRemoteSequenceApi api, ImageDecoder decoder, bool readOnly = false) { ArgumentNullException.ThrowIfNull(remote); ArgumentNullException.ThrowIfNull(api); ArgumentNullException.ThrowIfNull(decoder); _remote = remote; _api = api; + IsReadOnly = readOnly; _frames = remote.OpenFrames(decoder); _pixels = (IFrameSource)_frames; var stopping = _stopping.Token; @@ -61,6 +63,8 @@ public sealed class RemoteSequenceSource : ISequenceSource public bool IsRemote => true; + public bool IsReadOnly { get; } + public event Action? JobChanged; /// The server sequence's id. @@ -126,6 +130,7 @@ public sealed class RemoteSequenceSource : ISequenceSource var stored = _stored ?? throw new InvalidOperationException("LoadAsync first."); var merged = ProjectMerge.SameValues(stored, basis) ? project : ProjectMerge.Merge(basis, project, stored); if (ProjectMerge.SameValues(merged, stored)) return merged; + if (IsReadOnly) throw new InvalidOperationException(Loc.L("Editor.Error.RemoteReadOnly")); var hero = merged.HeroFrame == stored.HeroFrame ? (Guid?)null : HeroFrameId(merged); try { @@ -175,33 +180,30 @@ public sealed class RemoteSequenceSource : ISequenceSource private async Task ListenAsync(CancellationToken cancellationToken) { var failures = 0; - while (!cancellationToken.IsCancellationRequested) + try { - try + while (true) { - await foreach (var e in _api.EventsAsync(cancellationToken).ConfigureAwait(false)) + try { - failures = 0; - await OnEventAsync(e, cancellationToken).ConfigureAwait(false); + await foreach (var e in _api.EventsAsync(cancellationToken).ConfigureAwait(false)) + { + failures = 0; + await OnEventAsync(e, cancellationToken).ConfigureAwait(false); + } } + catch (Exception ex) when (ex is not OutOfMemoryException && !cancellationToken.IsCancellationRequested) + { + Log.Info("editor", $"Events of the server lost for {_remote.Sequence.DisplayTitle}: {ex.Message}"); + } + var delay = Math.Min(MaxBackoff.Ticks, MinBackoff.Ticks << Math.Min(failures++, 10)); + await Task.Delay(TimeSpan.FromTicks(delay), cancellationToken).ConfigureAwait(false); + await RefreshTrackedAsync(cancellationToken).ConfigureAwait(false); } - catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) - { - return; - } - catch (Exception ex) when (ex is not OutOfMemoryException) - { - Log.Info("editor", $"Events of the server lost for {_remote.Sequence.DisplayTitle}: {ex.Message}"); - } - try - { - await Task.Delay(TimeSpan.FromTicks(Math.Min(MaxBackoff.Ticks, MinBackoff.Ticks << Math.Min(failures++, 10))), cancellationToken).ConfigureAwait(false); - } - catch (OperationCanceledException) - { - return; - } - await RefreshTrackedAsync(cancellationToken).ConfigureAwait(false); + } + catch (OperationCanceledException) when (cancellationToken.IsCancellationRequested) + { + // The editor closed. } } @@ -209,7 +211,8 @@ public sealed class RemoteSequenceSource : ISequenceSource { switch (e) { - case JobProgressEvent progress when _jobs.TryGetValue(progress.JobId, out var job): + // A late progress event never brings a finished job back to running. + case JobProgressEvent progress when _jobs.TryGetValue(progress.JobId, out var job) && job.State is JobState.Queued or JobState.Running: Publish(job with { State = JobState.Running, diff --git a/src/Titano.App/Sections/SequenceViewModel.cs b/src/Titano.App/Sections/SequenceViewModel.cs index 6cc2cf5b..8848a451 100644 --- a/src/Titano.App/Sections/SequenceViewModel.cs +++ b/src/Titano.App/Sections/SequenceViewModel.cs @@ -117,7 +117,8 @@ public sealed class SequenceViewModel : SectionViewModel /// /// Where 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). + /// 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. /// private async Task OpenSourceAsync(AppServices services, Guid sequenceId) { @@ -134,10 +135,8 @@ public sealed class SequenceViewModel : SectionViewModel // 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")); - // An editor whose saves the server refuses would only lose edits. - if (!sync.Policy.CanEdit) throw new InvalidOperationException(Loc.L("Editor.Error.RemoteReadOnly")); var api = sync.ConnectEditor() ?? throw new InvalidOperationException(Loc.L("Editor.Error.Missing")); - return new RemoteSequenceSource(remote, api, decoder); + return new RemoteSequenceSource(remote, api, decoder, readOnly: !sync.Policy.CanEdit); } /// Set hero changed the frame the Library shows (any thread): its card loads the new thumbnail. diff --git a/src/Titano.App/Server/SyncHost.cs b/src/Titano.App/Server/SyncHost.cs index f7e4fb79..b0a05e41 100644 --- a/src/Titano.App/Server/SyncHost.cs +++ b/src/Titano.App/Server/SyncHost.cs @@ -58,6 +58,9 @@ public sealed class SyncHost(AppServices services) : ISyncConnector, IAsyncDispo /// The signed-in account may send files (originals, renders) to the server. public bool CanUpload => Allows(Permissions.Upload); + /// The signed-in account may queue renders on the server. + public bool CanRender => Allows(Permissions.Render); + /// Pauses uploads while the connection is metered and the option is on. public UploadHold Uploads { get; } = new(services); diff --git a/tests/Titano.App.Tests/Editor/EditorFixture.cs b/tests/Titano.App.Tests/Editor/EditorFixture.cs index 060b89c9..31e511e5 100644 --- a/tests/Titano.App.Tests/Editor/EditorFixture.cs +++ b/tests/Titano.App.Tests/Editor/EditorFixture.cs @@ -86,6 +86,8 @@ internal sealed class FakeSequenceSource(SyntheticSequence sequence, SequenceCon /// A server sequence: renders become one job per preset. public bool IsRemote { get; init; } + public bool IsReadOnly { get; init; } + /// Jobs returns. public List Jobs { get; } = []; diff --git a/tests/Titano.App.Tests/Editor/EditorSmokeTests.cs b/tests/Titano.App.Tests/Editor/EditorSmokeTests.cs index 03a24d8a..da87b604 100644 --- a/tests/Titano.App.Tests/Editor/EditorSmokeTests.cs +++ b/tests/Titano.App.Tests/Editor/EditorSmokeTests.cs @@ -9,6 +9,8 @@ using Titano.App.Infrastructure; using Titano.App.Sections; using Titano.App.Shell; using Titano.App.Tests.Windows; +using Titano.Core.Export; +using Titano.Core.Localization; using Titano.Core.Model; using Titano.Core.Project; using Titano.Testing; @@ -197,6 +199,20 @@ public sealed class EditorSmokeTests await editor.RenderAsync(JobPriority.User, batch: false); var queued = Assert.Contains(await editor.Session.Source.ListJobsAsync(CancellationToken.None), _ => true); Assert.Equal(JobKind.Render, queued.Kind); + + // Without the Edit right a server sequence is only shown: every change is disabled and says why. + var content = EditorFixture.Content(EditorFixture.Sunset); + var looking = new EditorSession(new FakeSequenceSource(EditorFixture.Sunset, content) { IsRemote = true, IsReadOnly = true }, content, []); + var viewer = new EditorViewModel(shell, looking, [], EncoderHost.Client); + await using (viewer) + { + Assert.False(viewer.IsEditable); + Assert.Equal(Loc.L("Tooltips.Editor.ReadOnly"), viewer.LockedToolTip); + Assert.Equal(Loc.L("Tooltips.Editor.ReadOnly"), viewer.Frames.HeroToolTip); + Assert.False(viewer.Frames.SetHeroCommand.CanExecute(null)); + Assert.False(viewer.OptimiseAllCommand.CanExecute(null)); + Assert.False(viewer.AnalyseCommand.CanExecute(null)); + } } finally { diff --git a/tests/Titano.App.Tests/Editor/RemoteSequenceSourceTests.cs b/tests/Titano.App.Tests/Editor/RemoteSequenceSourceTests.cs index 477fc3d7..02db0758 100644 --- a/tests/Titano.App.Tests/Editor/RemoteSequenceSourceTests.cs +++ b/tests/Titano.App.Tests/Editor/RemoteSequenceSourceTests.cs @@ -148,6 +148,33 @@ public sealed class RemoteSequenceSourceTests(TestContext context) } } + [Test] + public async Task AnAccountWithoutTheEditRightOnlyLooks() + { + var (source, api, _) = Open(readOnly: true); + await using (source) + { + var content = await source.LoadAsync(context.Cancellation); + Assert.True(source.IsReadOnly); + var session = new EditorSession(source, content, [], TimeSpan.FromMilliseconds(20)); + await using (session) + { + Assert.True(session.IsReadOnly); + Assert.False(session.Edit(p => p with { Exposure = p.Exposure with { ExposureOffsetEv = 0.5 } })); + Assert.False(session.SetHero(3)); + Assert.Empty(session.OptimiseAll()); + Assert.False(session.Undo()); + Assert.True(await session.FlushAsync(), "nothing waits for a save"); + } + + // The source refuses a change as well; the same project is no change. + await Assert.ThrowsAsync(() => + source.SaveProjectAsync(content.Project with { HeroFrame = 1 }, content.Project, context.Cancellation)); + Assert.True(ProjectMerge.SameValues(content.Project, await source.SaveProjectAsync(content.Project, content.Project, context.Cancellation))); + Assert.Empty(api.Edits); + } + } + [Test] public async Task AnalysesAndRendersArePostedToTheServerOnePerPreset() { @@ -220,6 +247,13 @@ public sealed class RemoteSequenceSourceTests(TestContext context) api.Jobs[other] = api.Job(other, "render", "queued"); api.Jobs[foreign] = api.Job(foreign, "render", "queued", Guid.CreateVersion7()); Assert.SequenceEqual([other], (await source.ListJobsAsync(context.Cancellation)).Select(j => j.Id), "active jobs of this sequence only"); + + // A late progress event of the finished job does not bring it back to running. + api.Publish(new JobProgressEvent(id, 19, 20, 2.5, 1)); + api.Jobs[other] = api.Job(other, "render", "running"); + api.Publish(new JobStateEvent(other, "running", null)); + await WaitAsync(() => Last(seen).Id == other); + lock (seen) Assert.Equal(JobState.Done, seen.Last(j => j.Id == id).State); } Assert.True(api.Disposed, "closing the editor closes its connection"); } @@ -237,11 +271,13 @@ public sealed class RemoteSequenceSourceTests(TestContext context) } } - private (RemoteSequenceSource Source, FakeRemoteSequenceApi Api, RemoteSequence Remote) Open(int frames = 6, int cached = int.MaxValue) => - Open(EditorFixture.Sequence(frames), cached); + private (RemoteSequenceSource Source, FakeRemoteSequenceApi Api, RemoteSequence Remote) Open(int frames = 6, int cached = int.MaxValue, + bool readOnly = false) => + Open(EditorFixture.Sequence(frames), cached, readOnly); /// A server sequence whose first proxies are on this PC (synthetic JPEGs). - private (RemoteSequenceSource Source, FakeRemoteSequenceApi Api, RemoteSequence Remote) Open(SyntheticSequence sunset, int cached = int.MaxValue) + private (RemoteSequenceSource Source, FakeRemoteSequenceApi Api, RemoteSequence Remote) Open(SyntheticSequence sunset, int cached = int.MaxValue, + bool readOnly = false) { var folder = context.CreateTempDirectory("proxies"); var sequence = new Sequence @@ -265,7 +301,7 @@ public sealed class RemoteSequenceSourceTests(TestContext context) } var remote = new RemoteSequence(Server, sequence, frames, files); var api = new FakeRemoteSequenceApi(sequence) { SettingsJson = new ProjectSettings().ToJson() }; - return (new RemoteSequenceSource(remote, api, DecoderFactory.CreateClient(null)), api, remote); + return (new RemoteSequenceSource(remote, api, DecoderFactory.CreateClient(null), readOnly), api, remote); } private static Job Last(List seen)