CI / Build and test (push) Successful in 8m14s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 7s
Release / Build, test and publish (push) Successful in 13m19s
CI / PostgreSQL 16 integration (push) Successful in 4m49s
CI / PostgreSQL 17 integration (push) Successful in 5m28s
CI / Docker image (push) Successful in 53s
Release / Server image (push) Failing after 10s
The owner renamed the product and moved the repository to the self-hosted Gitea (https://gitea.encke-hake.ts.net/BalboSoft/Chronos) for more control, and asked for Actions and a first automatic release with the server package and the Windows exe (docs/requests/2026-10-23-chronos-gitea.md). - Chronos everywhere: a byte-exact rename of contents and paths, then a per-language review of the forms the old name's ending had dictated. - Gitea instead of GitHub: the update check, licence, issue and support links read ChronosReleasesUrl; the update check takes the highest stable version, offers a pre-release build its final release and reports a repository it cannot see as a failed check. EULA, security policy and Gitea issue forms live at the repository root. - Gitea Actions for the Linux act_runner (.gitea/workflows): CI, release, nightly image and performance gates in the .NET SDK container with git checkout and the system SQLite. The release cross-compiles the Windows programs, checks their icon, version and DPI manifest, packs installers and zips, publishes the Gitea release and pushes the server image (REGISTRY_TOKEN). Windows-only tests run in an opt-in job on a Windows runner (WINDOWS_RUNNER). - New Chronos.Tools commands: zip, gitea-release, postgres-ci (replaces the docker-exec script, which Gitea's service containers do not allow; the throw-away server runs without durability) and pe-check. - Timed tests take their budget from TestTiming (CHRONOS_TEST_TIME_FACTOR, 3 on the shared runner; the weekly performance gates keep theirs). BREAKING CHANGE: programs, settings, data folders, file types, environment variables and the Docker image use the new name; nothing is migrated from Titano, which never had a release. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
286 lines
12 KiB
C#
286 lines
12 KiB
C#
using System.ComponentModel;
|
||
using System.Windows.Input;
|
||
using Chronos.App.Infrastructure;
|
||
using Chronos.App.Server;
|
||
using Chronos.App.Settings;
|
||
using Chronos.App.Shell;
|
||
using Chronos.Core.Export;
|
||
using Chronos.Core.Localization;
|
||
using Chronos.Ui.Controls;
|
||
using Chronos.Ui.Mvvm;
|
||
|
||
namespace Chronos.App.Sections;
|
||
|
||
/// <summary>
|
||
/// Server (BRIEF §12.7, Server.html): address with LAN-discovered servers, connect with trust-on-first-use and login,
|
||
/// status (name, version, latency, certificate), account and quota, sign out, the options of this PC (render node,
|
||
/// proxies kept offline, automatic project sync, uploads paused on metered networks) and the sync table (<see cref="Sync"/>).
|
||
/// The rail badge counts the settings conflicts waiting for a choice.
|
||
/// </summary>
|
||
public sealed class ServerViewModel : SectionViewModel
|
||
{
|
||
private readonly SyncFilterChip _conflicts;
|
||
private string _address;
|
||
private string? _errorText;
|
||
private ServerSession? _session;
|
||
|
||
public ServerViewModel(ShellViewModel shell)
|
||
: base(SectionKey.Server, "Icon.Server")
|
||
{
|
||
Shell = shell;
|
||
_address = ServerAddress.Display(shell.Services.Settings.ServerUrl);
|
||
ConnectCommand = new AsyncRelayCommand(ConnectAsync, () => !IsBusy && !IsConnected && Address.Trim().Length > 0);
|
||
DisconnectCommand = new RelayCommand(() => Session.Disconnect(), () => IsConnected);
|
||
SignOutCommand = new AsyncRelayCommand(SignOutAsync, () => IsConnected);
|
||
UseServerCommand = new RelayCommand(p =>
|
||
{
|
||
if (p is DiscoveredServer s) Address = s.Address;
|
||
else if (p is string text) Address = text;
|
||
});
|
||
CertificateCommand = new RelayCommand(ShowCertificate, () => Fingerprint is not null);
|
||
Sync = new SyncTableViewModel(shell);
|
||
_conflicts = Sync.Chips.Single(c => c.Filter == SyncFilter.Conflicts);
|
||
_conflicts.PropertyChanged += OnConflictsChanged;
|
||
}
|
||
|
||
/// <summary>Sequences of this PC and of the server, where they stand and what can be done.</summary>
|
||
public SyncTableViewModel Sync { get; }
|
||
|
||
public ShellViewModel Shell { get; }
|
||
|
||
private ServerSession Session => _session ?? Shell.Services.Server;
|
||
|
||
public ICommand ConnectCommand { get; }
|
||
public ICommand DisconnectCommand { get; }
|
||
public ICommand SignOutCommand { get; }
|
||
public ICommand UseServerCommand { get; }
|
||
public ICommand CertificateCommand { get; }
|
||
|
||
/// <summary>Servers found on the LAN plus recently used ones, for the ▾ list.</summary>
|
||
public IEnumerable<DiscoveredServer> KnownServers =>
|
||
Session.Discovered.Concat(Shell.Services.Settings.RecentServers
|
||
.Where(r => !Session.Discovered.Any(d => d.Address.Equals(r, StringComparison.OrdinalIgnoreCase)))
|
||
.Select(r => new DiscoveredServer(r, r)));
|
||
|
||
public bool HasKnownServers => KnownServers.Any();
|
||
|
||
/// <summary>What ▾ lists, or why it is disabled.</summary>
|
||
public string KnownToolTip => Loc.L(HasKnownServers ? "Tooltips.Server.Found" : "Tooltips.Server.NoneFound");
|
||
|
||
/// <summary>What Connect does, or why it is disabled.</summary>
|
||
public string ConnectToolTip => Loc.L(Address.Trim().Length > 0 ? "Tooltips.Server.Connect" : "Tooltips.Server.ConnectNoAddress");
|
||
|
||
public string Address
|
||
{
|
||
get => _address;
|
||
set
|
||
{
|
||
if (!Set(ref _address, value ?? string.Empty)) return;
|
||
OnPropertyChanged(nameof(ConnectToolTip));
|
||
CommandManager.InvalidateRequerySuggested();
|
||
}
|
||
}
|
||
|
||
public bool IsBusy => Session.IsBusy;
|
||
public bool IsConnected => Session.IsConnected;
|
||
public bool IsDisconnected => !Session.IsConnected;
|
||
|
||
/// <summary>One sentence about the last failure; null when none.</summary>
|
||
public string? ErrorText
|
||
{
|
||
get => _errorText;
|
||
private set => Set(ref _errorText, value);
|
||
}
|
||
|
||
// ---- Status row ----
|
||
public StatusKind StatusKind => IsConnected ? StatusKind.Online : IsBusy ? StatusKind.Running : ErrorText is null ? StatusKind.Offline : StatusKind.Error;
|
||
|
||
public string StatusText => IsConnected ? Loc.L("Server.Status.Connected")
|
||
: IsBusy ? Loc.L("Server.Status.Connecting")
|
||
: Session.HasSavedSession ? Loc.L("Server.Status.Disconnected")
|
||
: Loc.L("Server.Status.NotConnected");
|
||
|
||
/// <summary>"Studio NAS · v1.3.0 · 14 ms".</summary>
|
||
public string? ServerText
|
||
{
|
||
get
|
||
{
|
||
if (!IsConnected || Session.Flow.Info is not { } info) return null;
|
||
var parts = new List<string> { info.Name, Loc.L("Server.Version", info.Version) };
|
||
if (Session.Flow.Latency is { } latency) parts.Add(Loc.L("Server.Latency", Math.Max(1, (int)Math.Round(latency.TotalMilliseconds))));
|
||
return string.Join(Loc.Separator, parts);
|
||
}
|
||
}
|
||
|
||
/// <summary>Fingerprint of the trusted self-signed certificate; null for a publicly valid certificate.</summary>
|
||
public string? Fingerprint => IsConnected ? Session.TrustOf(Session.Flow.Info?.TlsFingerprint)?.Fingerprint : null;
|
||
|
||
/// <summary>"TLS 9A:3C:71:E0:… trusted 2026-09-01".</summary>
|
||
public string? CertificateText => Fingerprint is { } fp && Session.TrustOf(fp) is { } trust
|
||
? Loc.L("Server.Certificate.Trusted", Formatting.LeftToRight(ServerSession.ShortFingerprint(fp)), Formatting.Date(trust.TrustedAt))
|
||
: null;
|
||
|
||
public string CertificateToolTip => Loc.L("Tooltips.Server.CertificateTrusted");
|
||
|
||
// ---- Account row ----
|
||
public string? Username => Session.User?.Username;
|
||
public string Initial => Username is { Length: > 0 } u ? char.ToUpper(u[0], Loc.Culture).ToString() : string.Empty;
|
||
|
||
public string? RoleText => Session.User?.Role is { } role ? KnownRole(role) is { } known ? Loc.L("Server.Role." + known) : role : null;
|
||
|
||
public string? RoleToolTip => Session.User?.Role is { } role && KnownRole(role) is { } known ? Loc.L("Tooltips.Server.Role." + known) : null;
|
||
|
||
public bool HasQuota => Session.User is { QuotaBytes: > 0 };
|
||
|
||
public double QuotaFraction => Session.User is { QuotaBytes: > 0 } u ? Math.Clamp((double)u.UsedBytes / u.QuotaBytes, 0, 1) : 0;
|
||
|
||
/// <summary>"2.1 TB of 5 TB", or the used bytes when unlimited.</summary>
|
||
public string? QuotaText => Session.User is not { } u ? null
|
||
: u.QuotaBytes > 0 ? Loc.L("Server.Quota", Formatting.Bytes(u.UsedBytes), Formatting.Bytes(u.QuotaBytes))
|
||
: Loc.L("Server.QuotaUnlimited", Formatting.Bytes(u.UsedBytes));
|
||
|
||
// ---- Options ----
|
||
public bool RenderNodeOptIn
|
||
{
|
||
get => Shell.Services.Settings.RenderNodeOptIn;
|
||
set
|
||
{
|
||
if (Shell.Services.Settings.RenderNodeOptIn == value) return;
|
||
Shell.Services.Settings.RenderNodeOptIn = value;
|
||
Shell.Services.SaveSettings();
|
||
OnPropertyChanged();
|
||
}
|
||
}
|
||
|
||
/// <summary>The video encoders a render node on this PC offers the server.</summary>
|
||
private IReadOnlyList<EncoderRow> NodeEncoders => EncoderUse.Node(Shell.Settings.Encoders.Select(e => e.Row),
|
||
AppServices.AllowsHardware(Shell.Services.Settings.HardwareEncoding, ExportResolver.CustomId));
|
||
|
||
/// <summary>"HEVC · H.264 · AV1" beside "Offer this PC as render node" (BRIEF §12.7); null before the encoders are known.</summary>
|
||
public string? NodeCodecsText => EncoderUse.Codecs(NodeEncoders);
|
||
|
||
public string NodeCodecsToolTip => Loc.L("Tooltips.Server.NodeEncoders", string.Join(", ", NodeEncoders.Select(e => e.DisplayName)));
|
||
|
||
/// <summary>Keep the proxy caches of server sequences opened with proxies up to date on this PC.</summary>
|
||
public bool KeepProxiesOffline
|
||
{
|
||
get => Shell.Services.Settings.KeepProxiesOffline;
|
||
set => SetSyncOption(value, Shell.Services.Settings.KeepProxiesOffline, v => Shell.Services.Settings.KeepProxiesOffline = v);
|
||
}
|
||
|
||
/// <summary>Send and take project settings changed on one side without asking.</summary>
|
||
public bool SyncSettingsAutomatically
|
||
{
|
||
get => Shell.Services.Settings.SyncSettingsAutomatically;
|
||
set => SetSyncOption(value, Shell.Services.Settings.SyncSettingsAutomatically, v => Shell.Services.Settings.SyncSettingsAutomatically = v);
|
||
}
|
||
|
||
/// <summary>Pause uploads while the connection is metered.</summary>
|
||
public bool PauseUploadsOnMetered
|
||
{
|
||
get => Shell.Services.Settings.PauseUploadsOnMetered;
|
||
set
|
||
{
|
||
if (Shell.Services.Settings.PauseUploadsOnMetered == value) return;
|
||
Shell.Services.Settings.PauseUploadsOnMetered = value;
|
||
Shell.Services.SaveSettings();
|
||
Shell.Services.Sync.Uploads.Request();
|
||
OnPropertyChanged();
|
||
}
|
||
}
|
||
|
||
/// <summary>Re-reads values another screen changed (Settings › Server and Rendering).</summary>
|
||
public void Refresh()
|
||
{
|
||
OnPropertyChanged(nameof(RenderNodeOptIn));
|
||
OnPropertyChanged(nameof(NodeCodecsText));
|
||
OnPropertyChanged(nameof(NodeCodecsToolTip));
|
||
}
|
||
|
||
/// <summary>Restores the saved session and starts listening for LAN servers.</summary>
|
||
public async Task AttachAsync()
|
||
{
|
||
_session = Shell.Services.Server;
|
||
_session.PropertyChanged += OnSessionChanged;
|
||
_session.Discovered.CollectionChanged += (_, _) =>
|
||
{
|
||
OnPropertyChanged(nameof(KnownServers));
|
||
OnPropertyChanged(nameof(HasKnownServers));
|
||
if (Address.Length == 0 && Session.Discovered.Count > 0) Address = Session.Discovered[0].Address;
|
||
};
|
||
if (!Shell.Services.Environment.IsCapture) _session.StartDiscovery();
|
||
Shell.Settings.Encoders.CollectionChanged += OnEncodersChanged;
|
||
Sync.Attach();
|
||
await _session.RestoreAsync();
|
||
if (_session.Flow.Error is not ConnectError.None and var error && !_session.IsConnected) ErrorText = ServerSession.ErrorText(error);
|
||
}
|
||
|
||
public override void Dispose()
|
||
{
|
||
_conflicts.PropertyChanged -= OnConflictsChanged;
|
||
if (_session is not null) _session.PropertyChanged -= OnSessionChanged;
|
||
Shell.Settings.Encoders.CollectionChanged -= OnEncodersChanged;
|
||
Sync.Dispose();
|
||
base.Dispose();
|
||
}
|
||
|
||
/// <summary>The encoders next to the render-node option are listed on the first visit.</summary>
|
||
protected override void OnActivated()
|
||
{
|
||
if (Shell.Settings.Encoders.Count == 0 && !Shell.Settings.IsDetecting) _ = Shell.Settings.DetectEncodersAsync();
|
||
}
|
||
|
||
private void OnConflictsChanged(object? sender, PropertyChangedEventArgs e)
|
||
{
|
||
if (e.PropertyName is nameof(SyncFilterChip.Count) or "" or null) Badge = _conflicts.Count;
|
||
}
|
||
|
||
private void SetSyncOption(bool value, bool current, Action<bool> store, [System.Runtime.CompilerServices.CallerMemberName] string? name = null)
|
||
{
|
||
if (value == current) return;
|
||
store(value);
|
||
Shell.Services.SaveSettings();
|
||
Shell.Services.Sync.RequestRefresh();
|
||
OnPropertyChanged(name);
|
||
}
|
||
|
||
private async Task ConnectAsync()
|
||
{
|
||
ErrorText = null;
|
||
var connected = await Session.ConnectAsync(Address, Shell.Services.Dialogs);
|
||
if (connected)
|
||
{
|
||
Address = ServerAddress.Display(Session.SavedAddress);
|
||
return;
|
||
}
|
||
if (Session.Flow.Error is not ConnectError.None and var error) ErrorText = ServerSession.ErrorText(error);
|
||
}
|
||
|
||
private async Task SignOutAsync()
|
||
{
|
||
await Session.SignOutAsync();
|
||
ErrorText = null;
|
||
}
|
||
|
||
private void ShowCertificate()
|
||
{
|
||
if (Fingerprint is { } fingerprint) Session.ConfirmForget(fingerprint, Shell.Services.Dialogs);
|
||
}
|
||
|
||
private void OnEncodersChanged(object? sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
|
||
{
|
||
OnPropertyChanged(nameof(NodeCodecsText));
|
||
OnPropertyChanged(nameof(NodeCodecsToolTip));
|
||
}
|
||
|
||
private void OnSessionChanged(object? sender, PropertyChangedEventArgs e)
|
||
{
|
||
OnAllPropertiesChanged();
|
||
CommandManager.InvalidateRequerySuggested();
|
||
}
|
||
|
||
/// <summary>The <see cref="Core.Model.UserRole"/> name of a server role, or null for a role this build does not know.</summary>
|
||
private static string? KnownRole(string role) =>
|
||
Enum.TryParse<Core.Model.UserRole>(role, ignoreCase: true, out var parsed) ? parsed.ToString() : null;
|
||
}
|