diff --git a/client/src/app/models/profile.model.ts b/client/src/app/models/profile.model.ts index a3a090d..ce0876c 100644 --- a/client/src/app/models/profile.model.ts +++ b/client/src/app/models/profile.model.ts @@ -2,4 +2,6 @@ export class Profile { public provider: string; public userName: string; public expiration: Date; + public currentVersion: string; + public latestVersion: string; } diff --git a/client/src/app/navbar/navbar.component.html b/client/src/app/navbar/navbar.component.html index ce3f577..ad6d854 100644 --- a/client/src/app/navbar/navbar.component.html +++ b/client/src/app/navbar/navbar.component.html @@ -38,7 +38,7 @@ Settings - + @@ -61,3 +61,7 @@ +
+ Version {{ profile.latestVersion }} of RealDebrid Client was found. You are currently on version + {{ profile.currentVersion }}. +
diff --git a/client/src/app/navbar/navbar.component.scss b/client/src/app/navbar/navbar.component.scss index b4f314f..418af74 100644 --- a/client/src/app/navbar/navbar.component.scss +++ b/client/src/app/navbar/navbar.component.scss @@ -1,3 +1,7 @@ .no-premium { color: red; } + +.notification { + margin-top: 52px; +} \ No newline at end of file diff --git a/server/RdtClient.Data/Models/Internal/Profile.cs b/server/RdtClient.Data/Models/Internal/Profile.cs index df1baf9..79007d0 100644 --- a/server/RdtClient.Data/Models/Internal/Profile.cs +++ b/server/RdtClient.Data/Models/Internal/Profile.cs @@ -7,5 +7,7 @@ namespace RdtClient.Data.Models.Internal public String Provider { get; set; } public String UserName { get; set; } public DateTimeOffset? Expiration { get; set; } + public String CurrentVersion { get; set; } + public String LatestVersion { get; set; } } } diff --git a/server/RdtClient.Service/Services/Torrents.cs b/server/RdtClient.Service/Services/Torrents.cs index 958a2f4..5b22a90 100644 --- a/server/RdtClient.Service/Services/Torrents.cs +++ b/server/RdtClient.Service/Services/Torrents.cs @@ -333,7 +333,9 @@ namespace RdtClient.Service.Services { Provider = Settings.Get.Provider, UserName = user.Username, - Expiration = user.Expiration + Expiration = user.Expiration, + CurrentVersion = UpdateChecker.CurrentVersion, + LatestVersion = UpdateChecker.LatestVersion }; return profile; diff --git a/server/RdtClient.Service/Services/UpdateChecker.cs b/server/RdtClient.Service/Services/UpdateChecker.cs new file mode 100644 index 0000000..10cd43f --- /dev/null +++ b/server/RdtClient.Service/Services/UpdateChecker.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Newtonsoft.Json; + +namespace RdtClient.Service.Services +{ + public class UpdateChecker : BackgroundService + { + public static String CurrentVersion { get; set; } + public static String LatestVersion { get; set; } + + private readonly ILogger _logger; + + public UpdateChecker(ILogger logger) + { + _logger = logger; + } + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + var version = Assembly.GetEntryAssembly()?.GetName().Version?.ToString(); + + CurrentVersion = $"v{version[..version.LastIndexOf(".")]}"; + + _logger.LogInformation($"UpdateChecker started, currently on version {CurrentVersion}."); + + while (!stoppingToken.IsCancellationRequested) + { + try + { + var httpClient = new HttpClient(); + httpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue("RdtClient", CurrentVersion)); + var response = await httpClient.GetStringAsync($"https://api.github.com/repos/rogerfar/rdt-client/tags?per_page=1", stoppingToken); + + var gitHubReleases = JsonConvert.DeserializeObject>(response); + + if (gitHubReleases == null || gitHubReleases.Count == 0) + { + return; + } + + var latestRelease = gitHubReleases.First().Name; + + if (latestRelease != CurrentVersion) + { + _logger.LogInformation($"New version found on GitHub: {latestRelease}"); + } + + LatestVersion = latestRelease; + } + catch (Exception ex) + { + _logger.LogError(ex, "Unexpected error occurred in TorrentDownloadManager.Tick"); + } + + await Task.Delay(TimeSpan.FromHours(1), stoppingToken); + } + + _logger.LogInformation("UpdateChecker stopped."); + } + } + + public class GitHubReleasesResponse + { + [JsonProperty("name")] + public String Name { get; set; } + } +} diff --git a/server/RdtClient.Web/Program.cs b/server/RdtClient.Web/Program.cs index 64d6a22..1918396 100644 --- a/server/RdtClient.Web/Program.cs +++ b/server/RdtClient.Web/Program.cs @@ -112,6 +112,7 @@ namespace RdtClient.Web .ConfigureServices((hostContext, services) => { services.AddHostedService(); + services.AddHostedService(); }) .ConfigureWebHostDefaults(webBuilder => {