fix(app): viewers open server sequences with proxies, the editor follows the sign-in
An account without Edit is offered Open with proxies on a server that keeps projects and checks nothing out, since it could never push. The editor of a server's workspace project connects with the sign-in in use at each call, so a project opened signed out renders once signed in; SyncHost tells every session start and stop so workspace projects read their state again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cdd29f8e84
commit
48d8158fd7
8 files changed
+165
-24
No files matched your search
@@ -62,6 +62,9 @@ public sealed class SampleData
|
||||
|
||||
private SampleData(AppServices services) => _services = services;
|
||||
|
||||
/// <summary>What the sample server says it can do (none: an older server, whose sequences open with proxies); tests set it.</summary>
|
||||
public IReadOnlyList<string> Capabilities { get; set; } = [];
|
||||
|
||||
/// <summary>The server-only sequence whose proxies <see cref="CacheProxiesAsync"/> keeps on this PC (Sunrise over Superga).</summary>
|
||||
public Guid ProxiedSequenceId => _sunrise;
|
||||
|
||||
@@ -762,7 +765,7 @@ public sealed class SampleData
|
||||
{
|
||||
await Task.Delay(14, ct);
|
||||
if (!trusted.Contains(ServerFingerprint, StringComparer.OrdinalIgnoreCase)) throw new UntrustedCertificateException(ServerFingerprint);
|
||||
return new ServerInfo("Studio NAS", "1.3.0", 1, [], ServerFingerprint, [], new ServerLimits(0, 0));
|
||||
return new ServerInfo("Studio NAS", "1.3.0", 1, sample.Capabilities, ServerFingerprint, [], new ServerLimits(0, 0));
|
||||
}
|
||||
|
||||
public Task<LoginResponse> LoginAsync(string username, string password, CancellationToken ct)
|
||||
|
||||
@@ -32,11 +32,25 @@ public interface IProjectRenders
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A workspace project's home when it is a server (owner review 2, R8, phase 5b): the connection its analyses and renders
|
||||
/// travel on, which the source owns; null while this PC is not signed in to that server (the project still opens from the
|
||||
/// workspace, its jobs are refused saying so).
|
||||
/// A workspace project's home when it is a server (owner review 2, R8, phase 5b): how the source connects for its analyses
|
||||
/// and renders (<paramref name="connect"/>: a connection the source owns, null while this PC is not signed in to that
|
||||
/// server, when the project still opens from the workspace and its jobs are refused saying so), and the sign-in it would
|
||||
/// connect with (<paramref name="session"/>): when that changes (signed in, out, or anew), the source connects again.
|
||||
/// </summary>
|
||||
public sealed record WorkspaceServerHome(IRemoteSequenceApi? Api);
|
||||
public sealed class WorkspaceServerHome(Func<IRemoteSequenceApi?> connect, Func<object?> session)
|
||||
{
|
||||
/// <summary>One connection for good (null: never signed in), as a test or a capture holds it.</summary>
|
||||
public WorkspaceServerHome(IRemoteSequenceApi? api)
|
||||
: this(() => api, () => api)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>The sign-in <see cref="Connect"/> would use now; compared by reference.</summary>
|
||||
public object? Session => session();
|
||||
|
||||
/// <summary>A new connection of the current sign-in; null while signed out.</summary>
|
||||
public IRemoteSequenceApi? Connect() => connect();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A workspace project open in the editor (owner review 2, R8: editing happens in the workspace, never inside the
|
||||
@@ -71,6 +85,9 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
|
||||
private IRenderFrameSource? _frames;
|
||||
private IFrameSource? _pixels;
|
||||
private ServerJobs? _serverJobs;
|
||||
private IRemoteSequenceApi? _api;
|
||||
private object? _apiSession;
|
||||
private bool _connected;
|
||||
private int _frameCount;
|
||||
private int _framesVersion = -1;
|
||||
private Guid[] _frameIds = [];
|
||||
@@ -273,12 +290,37 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
|
||||
/// <summary>The server's jobs of the sequence, followed from now on; null while this PC is not signed in to the server.</summary>
|
||||
private ServerJobs? ServerJobsOf(Guid sequenceId, string title)
|
||||
{
|
||||
if (_server?.Api is not { } api) return null;
|
||||
if (Api() is not { } api) return null;
|
||||
lock (_gate)
|
||||
{
|
||||
if (Volatile.Read(ref _disposed) == 1 || !ReferenceEquals(api, _api)) return null;
|
||||
return _serverJobs ??= new ServerJobs(api, sequenceId, title, job => JobChanged?.Invoke(job));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The connection of the sign-in in use now: made at first use, and again once the sign-in changed (the jobs followed
|
||||
/// on the old one stop with it, so a project opened signed out renders once signed in); null while signed out.
|
||||
/// </summary>
|
||||
private IRemoteSequenceApi? Api()
|
||||
{
|
||||
if (_server is null) return null;
|
||||
var session = _server.Session;
|
||||
IRemoteSequenceApi? api, stale;
|
||||
ServerJobs? staleJobs;
|
||||
lock (_gate)
|
||||
{
|
||||
if (Volatile.Read(ref _disposed) == 1) return null;
|
||||
return _serverJobs ??= new ServerJobs(api, sequenceId, title, job => JobChanged?.Invoke(job));
|
||||
if (_connected && ReferenceEquals(session, _apiSession)) return _api;
|
||||
(stale, staleJobs) = (_api, _serverJobs);
|
||||
_serverJobs = null;
|
||||
_api = api = _server.Connect();
|
||||
(_apiSession, _connected) = (session, true);
|
||||
}
|
||||
// The jobs own their connection.
|
||||
if (staleJobs is not null) _ = staleJobs.DisposeAsync().AsTask();
|
||||
else stale?.Dispose();
|
||||
return api;
|
||||
}
|
||||
|
||||
/// <summary>The server's deep report when it describes these frames, else the copy the workspace took; whether one of another number of frames was read instead.</summary>
|
||||
@@ -325,7 +367,7 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
|
||||
{
|
||||
if (Workspace is not { } workspace || MediaFramesVersion < 0) return false;
|
||||
if (_server is null) return await _db.Sequences.GetAsync(workspace.Home.SequenceId, cancellationToken) is { } row && row.FramesVersion != MediaFramesVersion;
|
||||
if (_server.Api is not { } api) return false;
|
||||
if (Api() is not { } api) return false;
|
||||
try
|
||||
{
|
||||
if ((await api.GetSequenceAsync(workspace.Home.SequenceId, cancellationToken)).FramesVersion != MediaFramesVersion) return true;
|
||||
@@ -463,7 +505,7 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
|
||||
public async Task<IReadOnlyList<Job>> ListJobsAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
if (_server is null) return (await _db.Jobs.ListAsync(null, JobsListed, null, cancellationToken)).Items;
|
||||
if (Volatile.Read(ref _serverJobs) is not { } jobs) return [];
|
||||
if (Api() is null || Volatile.Read(ref _serverJobs) is not { } jobs) return [];
|
||||
try
|
||||
{
|
||||
return await jobs.ListAsync(cancellationToken);
|
||||
@@ -554,17 +596,18 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
|
||||
if (_engine is not null) _engine.JobChanged -= OnJobChanged;
|
||||
List<IRenderFrameSource> sources;
|
||||
ServerJobs? jobs;
|
||||
IRemoteSequenceApi? api;
|
||||
lock (_gate)
|
||||
{
|
||||
sources = [.. _retired];
|
||||
if (_frames is not null) sources.Add(_frames);
|
||||
_retired.Clear();
|
||||
(_frames, _pixels) = (null, null);
|
||||
(jobs, _serverJobs) = (_serverJobs, null);
|
||||
(jobs, _serverJobs, api, _api) = (_serverJobs, null, _api, null);
|
||||
}
|
||||
// The server's connection is the source's: it closes with it, also when no read made the jobs' listener.
|
||||
if (jobs is not null) await jobs.DisposeAsync();
|
||||
else _server?.Api?.Dispose();
|
||||
else api?.Dispose();
|
||||
foreach (var source in sources)
|
||||
{
|
||||
if (source is IAsyncDisposable disposable) await disposable.DisposeAsync();
|
||||
@@ -574,8 +617,7 @@ public sealed class WorkspaceSequenceSource : ISequenceSource, IProjectRenders
|
||||
/// <summary>The server's jobs of the project's sequence, or why there are none.</summary>
|
||||
/// <exception cref="EditorException">This PC is not signed in to the server of the project.</exception>
|
||||
private ServerJobs ServerJobsOrThrow() =>
|
||||
Volatile.Read(ref _serverJobs)
|
||||
?? (Workspace is { } workspace ? ServerJobsOf(workspace.Home.SequenceId, Project.ReadBundle().Sequence.Title ?? string.Empty) : null)
|
||||
(Workspace is { } workspace ? ServerJobsOf(workspace.Home.SequenceId, Project.ReadBundle().Sequence.Title ?? string.Empty) : null)
|
||||
?? throw new EditorException(Loc.L("Editor.Error.SignedOut"));
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -726,12 +726,15 @@ public sealed class SequenceViewModel : SectionViewModel
|
||||
{
|
||||
TakeRequest(remoteId);
|
||||
workspace.Remember(remoteId, entry.ProjectId);
|
||||
// Its analyses and renders travel on a connection of the signed-in session, when that is the project's server.
|
||||
var api = string.Equals(sync.Server, entry.Home.Server, StringComparison.OrdinalIgnoreCase) ? sync.ConnectEditor() : null;
|
||||
return new ServerOpen((new WorkspaceSequenceSource(workspace.Sync, entry.ProjectId, db, decoder, services.Engine, new WorkspaceServerHome(api)),
|
||||
entry.SequenceTitle));
|
||||
// Its analyses and renders travel on a connection of the signed-in session, when that is the project's server:
|
||||
// made again whenever the sign-in changes, so a project opened signed out renders once signed in.
|
||||
var server = entry.Home.Server;
|
||||
var editorHome = new WorkspaceServerHome(() => string.Equals(sync.Server, server, StringComparison.OrdinalIgnoreCase) ? sync.ConnectEditor() : null,
|
||||
() => sync.Session);
|
||||
return new ServerOpen((new WorkspaceSequenceSource(workspace.Sync, entry.ProjectId, db, decoder, services.Engine, editorHome), entry.SequenceTitle));
|
||||
}
|
||||
if (sync.ServerHome(remoteId) is not { } home) return null;
|
||||
// An account that may not edit checks nothing out: it is shown with proxies, read-only, as on an older server.
|
||||
if (!sync.Policy.CanEdit || sync.ServerHome(remoteId) is not { } home) return null;
|
||||
TakeRequest(remoteId);
|
||||
try
|
||||
{
|
||||
|
||||
@@ -100,7 +100,8 @@ public sealed class SyncHost(AppServices services) : ISyncConnector, IAsyncDispo
|
||||
|
||||
/// <summary>
|
||||
/// A project of a sequence of the signed-in server changed there (the server's key, and its <c>projectChanged</c>), or,
|
||||
/// with null, changes may have been missed while its events were lost (any thread).
|
||||
/// with null, changes may have been missed while its events were lost, or the session with that server started or
|
||||
/// stopped (its projects become reachable, or offline) (any thread).
|
||||
/// </summary>
|
||||
public event Action<string, ProjectChangedEvent?>? ProjectChanged;
|
||||
|
||||
@@ -139,6 +140,9 @@ public sealed class SyncHost(AppServices services) : ISyncConnector, IAsyncDispo
|
||||
engine.JobChanged += OnJobChanged;
|
||||
}
|
||||
|
||||
/// <summary>The sign-in <see cref="ConnectEditor"/> uses now (another object once signed in anew); null while signed out.</summary>
|
||||
public object? Session => Volatile.Read(ref _credentials);
|
||||
|
||||
/// <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;
|
||||
@@ -260,7 +264,10 @@ public sealed class SyncHost(AppServices services) : ISyncConnector, IAsyncDispo
|
||||
await previous.ConfigureAwait(false);
|
||||
if (Volatile.Read(ref _running) is { } running && wanted is { } same && running.Credentials.Address == same.Address && running.Credentials.Token == same.Token)
|
||||
return;
|
||||
var stopped = Volatile.Read(ref _running)?.Remote.Server;
|
||||
await StopAsync().ConfigureAwait(false);
|
||||
// The projects of the server left are offline now: their state is read again.
|
||||
if (stopped is not null) ProjectChanged?.Invoke(stopped, null);
|
||||
if (wanted is not { } start || Service is not { } service)
|
||||
{
|
||||
Changed?.Invoke();
|
||||
@@ -274,6 +281,7 @@ public sealed class SyncHost(AppServices services) : ISyncConnector, IAsyncDispo
|
||||
Volatile.Write(ref _running, new Running(agent, remote, start));
|
||||
Log.Info("sync", $"Comparing with {remote.Server}");
|
||||
Changed?.Invoke();
|
||||
ProjectChanged?.Invoke(remote.Server, null);
|
||||
}
|
||||
|
||||
private async Task StopAsync()
|
||||
|
||||
@@ -235,15 +235,15 @@ public static class SyncText
|
||||
actions.Add(SyncAction.Upload);
|
||||
break;
|
||||
// A server that keeps projects edits its sequences in the workspace; an older one's open with proxies, the
|
||||
// workspace offered disabled with the reason (phase 5b).
|
||||
case SyncStatus.RemoteOnly or SyncStatus.ProxiesOnly when rights.KeepsProjects:
|
||||
// workspace offered disabled with the reason (phase 5b). An account that may not edit only looks: with proxies.
|
||||
case SyncStatus.RemoteOnly or SyncStatus.ProxiesOnly when rights is { KeepsProjects: true, CanEdit: true }:
|
||||
actions.Add(SyncAction.OpenInWorkspace);
|
||||
if (rights.CanFetchOriginals) actions.Add(SyncAction.DownloadOriginals);
|
||||
break;
|
||||
case SyncStatus.RemoteOnly or SyncStatus.ProxiesOnly:
|
||||
actions.Add(SyncAction.OpenWithProxies);
|
||||
if (rights.CanFetchOriginals) actions.Add(SyncAction.DownloadOriginals);
|
||||
actions.Add(SyncAction.OpenInWorkspace);
|
||||
if (!rights.KeepsProjects) actions.Add(SyncAction.OpenInWorkspace);
|
||||
break;
|
||||
case SyncStatus.LocalAhead when entry.Link is { MissingRemote: > 0 }:
|
||||
if (rights.CanUpload) actions.Add(SyncAction.Upload);
|
||||
|
||||
Reference in new issue
Block a user