From f56d48890878ff910d9100c77558bf901a58a47b Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 9 Sep 2021 09:01:03 -0500 Subject: group state records --- src/slskd/Application/ApplicationState.cs | 68 ++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 5 deletions(-) (limited to 'src/slskd/Application/ApplicationState.cs') diff --git a/src/slskd/Application/ApplicationState.cs b/src/slskd/Application/ApplicationState.cs index e3b41a66..c9322eb3 100644 --- a/src/slskd/Application/ApplicationState.cs +++ b/src/slskd/Application/ApplicationState.cs @@ -17,19 +17,77 @@ namespace slskd { + using System.Net; + using System.Text.Json.Serialization; + using Soulseek; + /// /// Application service state. /// - public record ApplicationState() + public record ApplicationState { - public string Version { get; init; } = Program.InformationalVersion; - public string LatestVersion { get; init; } = Program.InformationalVersion; - public bool? UpdateAvailable { get; init; } = null; - public bool IsCanary { get; init; } = Program.IsCanary; + public VersionState Version { get; init; } = new VersionState(); public bool PendingReconnect { get; init; } public bool PendingRestart { get; init; } public bool PendingShareRescan { get; init; } public ServerState Server { get; init; } = new ServerState(); public SharedFileCacheState SharedFileCache { get; init; } = new SharedFileCacheState(); } + + public record VersionState + { + public string Current { get; init; } = Program.InformationalVersion; + public string Latest { get; init; } = null; + public bool? IsUpdateAvailable { get; init; } = null; + public bool IsCanary { get; init; } = Program.IsCanary; + } + + public record ServerState + { + public string Address { get; init; } + + [JsonConverter(typeof(IPEndPointConverter))] + public IPEndPoint IPEndPoint { get; init; } + public SoulseekClientStates State { get; init; } + public string Username { get; init; } + public bool IsConnected => State.HasFlag(SoulseekClientStates.Connected); + public bool IsLoggedIn => State.HasFlag(SoulseekClientStates.LoggedIn); + public bool IsTransitioning => State.HasFlag(SoulseekClientStates.Connecting) || State.HasFlag(SoulseekClientStates.Disconnecting) || State.HasFlag(SoulseekClientStates.LoggingIn); + } + + /// + /// Share cache state. + /// + public record SharedFileCacheState + { + /// + /// Gets a value indicating whether the cache is being filled. + /// + public bool Filling { get; init; } = false; + + /// + /// Gets a value indicating whether the cache is faulted. + /// + public bool Faulted { get; init; } = false; + + /// + /// Gets the current fill progress. + /// + public double FillProgress { get; init; } + + /// + /// Gets the number of cached directories. + /// + public int Directories { get; init; } + + /// + /// Gets the number of cached files. + /// + public int Files { get; init; } + + /// + /// Gets the number of directories excluded by filters. + /// + public int ExcludedDirectories { get; init; } + } } \ No newline at end of file -- cgit v1.2.3