From edf86bfb54d31c1a0b02e7d416806d260dd5b7f2 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 6 Sep 2021 22:12:09 -0500 Subject: add Program.IsCanary, silence noisy logs --- src/slskd/Program.cs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 4489487a..ab14ab9e 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -114,6 +114,21 @@ namespace slskd /// public static string Version { get; } = $"{AssemblyVersion} ({InformationalVersion})"; + /// + /// Gets a value indicating whether the current version is a Canary build. + /// + public static bool IsCanary { get; } = InformationalVersion.EndsWith("65534"); + + /// + /// Gets the API url for the application repository. + /// + public static string RepositoryAPIUrl { get; } = "https://api.github.com/repos/slskd/slskd"; + + /// + /// Gets the API url for the latest application release. + /// + public static string RepositoryAPILatestReleaseUrl { get; } = $"{RepositoryAPIUrl}/releases/latest"; + private static IConfigurationRoot Configuration { get; set; } private static OptionsAtStartup OptionsAtStartup { get; } = new OptionsAtStartup(); @@ -209,7 +224,8 @@ namespace slskd Log.Logger = (OptionsAtStartup.Debug ? new LoggerConfiguration().MinimumLevel.Debug() : new LoggerConfiguration().MinimumLevel.Information()) .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) - .MinimumLevel.Override("slskd.API.Authentication.PassthroughAuthenticationHandler", LogEventLevel.Information) + .MinimumLevel.Override("System.Net.Http.HttpClient", OptionsAtStartup.Debug ? LogEventLevel.Warning : LogEventLevel.Fatal) + .MinimumLevel.Override("slskd.Authentication.PassthroughAuthenticationHandler", LogEventLevel.Warning) .Enrich.WithProperty("Version", Version) .Enrich.WithProperty("InstanceName", OptionsAtStartup.InstanceName) .Enrich.WithProperty("InvocationId", InvocationId) -- cgit v1.2.3 From 4407fadc62b4edbe51854aa94b74b990b88e8316 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Wed, 8 Sep 2021 09:13:53 -0500 Subject: remove old version check --- .../Application/Management/IManagementService.cs | 6 --- .../Application/Management/ManagementService.cs | 49 +--------------------- src/slskd/Program.cs | 10 ----- 3 files changed, 1 insertion(+), 64 deletions(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Application/Management/IManagementService.cs b/src/slskd/Application/Management/IManagementService.cs index ba5ba69a..9a06d961 100644 --- a/src/slskd/Application/Management/IManagementService.cs +++ b/src/slskd/Application/Management/IManagementService.cs @@ -58,11 +58,5 @@ namespace slskd.Management /// /// The operation context. Task RescanSharesAsync(); - - /// - /// Gets the version of the latest application release. - /// - /// The operation context. - Task CheckVersionAsync(); } } \ No newline at end of file diff --git a/src/slskd/Application/Management/ManagementService.cs b/src/slskd/Application/Management/ManagementService.cs index 0aff7658..4319c9e3 100644 --- a/src/slskd/Application/Management/ManagementService.cs +++ b/src/slskd/Application/Management/ManagementService.cs @@ -20,9 +20,6 @@ using Microsoft.Extensions.Options; namespace slskd.Management { using System; - using System.Net.Http; - using System.Net.Http.Json; - using System.Text.Json; using System.Threading.Tasks; using Serilog; using Soulseek; @@ -39,22 +36,18 @@ namespace slskd.Management /// The state monitor for application service state. /// The Soulseek client. /// The shared file cache. - /// The HttpClientFactory to use. public ManagementService( IOptionsMonitor optionsMonitor, IStateMonitor applicationStateMonitor, ISoulseekClient soulseekClient, - ISharedFileCache sharedFileCache, - IHttpClientFactory httpClientFactory) + ISharedFileCache sharedFileCache) { OptionsMonitor = optionsMonitor; ApplicationStateMonitor = applicationStateMonitor; Client = soulseekClient; SharedFileCache = sharedFileCache; - HttpClientFactory = httpClientFactory; } - private IHttpClientFactory HttpClientFactory { get; } private ILogger Log { get; } = Serilog.Log.ForContext(); /// @@ -105,45 +98,5 @@ namespace slskd.Management /// /// The operation context. public Task RescanSharesAsync() => SharedFileCache.FillAsync(); - - /// - /// Gets the version of the latest application release. - /// - /// The operation context. - public async Task CheckVersionAsync() - { - if (Program.InformationalVersion.EndsWith("65534")) - { - Log.Information("Skipping version check for Canary build; check for updates manually."); - } - - try - { - using var http = HttpClientFactory.CreateClient(); - http.DefaultRequestHeaders.UserAgent.TryParseAdd(Program.AppName + Program.Version); - - Log.Information("Checking {LatestReleaseUrl} for latest version", Program.RepositoryAPILatestReleaseUrl); - - var response = await http.GetFromJsonAsync(Program.RepositoryAPILatestReleaseUrl); - var latestVersion = Version.Parse(response.RootElement.GetProperty("tag_name").GetString()); - var currentVersion = Version.Parse(Program.InformationalVersion); - - if (latestVersion > currentVersion) - { - ApplicationStateMonitor.SetValue(state => state with { LatestVersion = latestVersion.ToString(), UpdateAvailable = true }); - Log.Information("A new version is available! {CurrentVersion} -> {LatestVersion}", currentVersion, latestVersion); - } - else - { - Log.Information("Version {Version} is up to date.", currentVersion); - } - - } - catch (Exception ex) - { - Log.Warning("Failed to check version: {Message}", ex.Message); - throw; - } - } } } \ No newline at end of file diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index ab14ab9e..529388a1 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -119,16 +119,6 @@ namespace slskd /// public static bool IsCanary { get; } = InformationalVersion.EndsWith("65534"); - /// - /// Gets the API url for the application repository. - /// - public static string RepositoryAPIUrl { get; } = "https://api.github.com/repos/slskd/slskd"; - - /// - /// Gets the API url for the latest application release. - /// - public static string RepositoryAPILatestReleaseUrl { get; } = $"{RepositoryAPIUrl}/releases/latest"; - private static IConfigurationRoot Configuration { get; set; } private static OptionsAtStartup OptionsAtStartup { get; } = new OptionsAtStartup(); -- cgit v1.2.3 From b36d8286b1c227782ad7cb4278cab32b6abc6168 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 9 Sep 2021 09:01:55 -0500 Subject: force version to 0.0.0.0 if defaulted --- src/slskd/Program.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 529388a1..ec672f23 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -89,7 +89,7 @@ namespace slskd /// /// Inaccurate when running locally. /// - public static Version AssemblyVersion { get; } = Assembly.GetExecutingAssembly().GetName().Version; + public static Version AssemblyVersion { get; } = Assembly.GetExecutingAssembly().GetName().Version.Equals(new Version(1,0,0,0)) ? new Version(0, 0, 0, 0) : Assembly.GetExecutingAssembly().GetName().Version; /// /// Gets the informational version of the application, including the git sha at the latest commit. @@ -97,7 +97,7 @@ namespace slskd /// /// Inaccurate when running locally. /// - public static string InformationalVersion { get; } = Assembly.GetExecutingAssembly().GetCustomAttribute().InformationalVersion; + public static string InformationalVersion { get; } = Assembly.GetExecutingAssembly().GetCustomAttribute().InformationalVersion == "1.0.0" ? "0.0.0" : Assembly.GetExecutingAssembly().GetCustomAttribute().InformationalVersion; /// /// Gets the unique Id of this application invocation. -- cgit v1.2.3