aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-09-08 09:13:30 -0500
committerJP Dillingham <jpdillingham@gmail.com>2021-09-08 09:13:30 -0500
commit161f3517d703658bf296282a2e9fab44f9149134 (patch)
treece2f91dfd5c075604f02fe9c5f48bae70665147c
parentca5c375ed5198dc283a51f28b232df4c72e3e04f (diff)
downloadslskd-161f3517d703658bf296282a2e9fab44f9149134.tar.gz
add IApplication interface, implement version check, add Application to DI
-rw-r--r--src/slskd/Application/Application.cs63
-rw-r--r--src/slskd/Application/IApplication.cs27
-rw-r--r--src/slskd/Startup.cs5
3 files changed, 85 insertions, 10 deletions
diff --git a/src/slskd/Application/Application.cs b/src/slskd/Application/Application.cs
index aa593679..903ae143 100644
--- a/src/slskd/Application/Application.cs
+++ b/src/slskd/Application/Application.cs
@@ -39,7 +39,7 @@ namespace slskd
using Soulseek;
using Soulseek.Diagnostics;
- public class Application : IHostedService
+ public class Application : IApplication
{
private static readonly int ReconnectMaxDelayMilliseconds = 300000; // 5 minutes
@@ -161,6 +161,19 @@ namespace slskd
public async Task StartAsync(CancellationToken cancellationToken)
{
+ Logger.Information("Client started");
+ Logger.Information("Listening on port {Port}", OptionsAtStartup.Soulseek.ListenPort);
+
+ if (OptionsAtStartup.Soulseek.Connection.Proxy.Enabled)
+ {
+ Logger.Information($"Using Proxy {OptionsAtStartup.Soulseek.Connection.Proxy.Address}:{OptionsAtStartup.Soulseek.Connection.Proxy.Port}");
+ }
+
+ if (!OptionsAtStartup.NoVersionCheck)
+ {
+ _ = CheckVersionAsync();
+ }
+
if (OptionsAtStartup.NoShareScan)
{
Logger.Warning("Not scanning shares; 'no-share-scan' option is enabled. Search and browse results will remain disabled until a manual scan is completed.");
@@ -170,14 +183,6 @@ namespace slskd
_ = SharedFileCache.FillAsync();
}
- if (OptionsAtStartup.Soulseek.Connection.Proxy.Enabled)
- {
- Logger.Information($"Using Proxy {OptionsAtStartup.Soulseek.Connection.Proxy.Address}:{OptionsAtStartup.Soulseek.Connection.Proxy.Port}");
- }
-
- Logger.Information("Client started");
- Logger.Information("Listening on port {Port}", OptionsAtStartup.Soulseek.ListenPort);
-
if (OptionsAtStartup.NoConnect)
{
Logger.Warning("Not connecting to the Soulseek server; 'no-connect' option is enabled");
@@ -200,6 +205,46 @@ namespace slskd
return Task.CompletedTask;
}
+ /// <summary>
+ /// Gets the version of the latest application release.
+ /// </summary>
+ /// <returns>The operation context.</returns>
+ public async Task CheckVersionAsync()
+ {
+ if (Program.InformationalVersion.EndsWith("65534"))
+ {
+ Logger.Information("Skipping version check for Canary build; check for updates manually.");
+ }
+
+ Logger.Information("Checking GitHub Releases for latest version");
+
+ try
+ {
+
+ var latestVersion = await GitHub.GetLatestReleaseVersion(
+ organization: Program.AppName,
+ repository: Program.AppName,
+ userAgent: $"{Program.AppName} v{Program.InformationalVersion}");
+
+ if (latestVersion > Program.AssemblyVersion)
+ {
+ StateMonitor.SetValue(state => state with { LatestVersion = latestVersion.ToString(), UpdateAvailable = true });
+ Logger.Information("A new version is available! {CurrentVersion} -> {LatestVersion}", Program.AssemblyVersion, latestVersion);
+ }
+ else
+ {
+ StateMonitor.SetValue(state => state with { LatestVersion = Program.AssemblyVersion.ToString(), UpdateAvailable = false });
+ Logger.Information("Version {CurrentVersion} is up to date.", Program.AssemblyVersion);
+ }
+
+ }
+ catch (Exception ex)
+ {
+ Logger.Warning("Failed to check version: {Message}", ex.Message);
+ throw;
+ }
+ }
+
private async Task OptionsMonitor_OnChange(Options newOptions)
{
// this code is known to fire more than once per update. i'm not sure
diff --git a/src/slskd/Application/IApplication.cs b/src/slskd/Application/IApplication.cs
new file mode 100644
index 00000000..45cf0a10
--- /dev/null
+++ b/src/slskd/Application/IApplication.cs
@@ -0,0 +1,27 @@
+// <copyright file="IApplication.cs" company="slskd Team">
+// Copyright (c) slskd Team. All rights reserved.
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published
+// by the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see https://www.gnu.org/licenses/.
+// </copyright>
+
+namespace slskd
+{
+ using System.Threading.Tasks;
+ using Microsoft.Extensions.Hosting;
+
+ public interface IApplication : IHostedService
+ {
+ public Task CheckVersionAsync();
+ }
+}
diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs
index 15ae2025..5c83fed3 100644
--- a/src/slskd/Startup.cs
+++ b/src/slskd/Startup.cs
@@ -218,7 +218,10 @@ namespace slskd
services.AddSingleton<IPushbulletService, PushbulletService>();
- services.AddHostedService<Application>();
+ services.AddSingleton<IApplication, Application>();
+ services.AddHostedService(p => p.GetRequiredService<IApplication>());
+
+ // todo: add public methods to Application until this is no longer necessary
services.AddSingleton(_ => Application.SoulseekClient);
}