diff --git a/Totoro.Core/Contracts/IUpdateService.cs b/Totoro.Core/Contracts/IUpdateService.cs index 9f726ba5..84da4cb1 100644 --- a/Totoro.Core/Contracts/IUpdateService.cs +++ b/Totoro.Core/Contracts/IUpdateService.cs @@ -5,6 +5,7 @@ public interface IUpdateService IObservable OnUpdateAvailable { get; } Task DownloadUpdate(VersionInfo versionInfo); void InstallUpdate(VersionInfo versionInfo); + ValueTask GetCurrentVersionInfo(); } public class VersionInfo @@ -13,5 +14,6 @@ public class VersionInfo public string Details { get; set; } public string Url { get; set; } public string FilePath { get; set; } + public string Body { get; set; } } } diff --git a/Totoro.Core/Contracts/IViewService.cs b/Totoro.Core/Contracts/IViewService.cs index d65bd736..9cfb44a2 100644 --- a/Totoro.Core/Contracts/IViewService.cs +++ b/Totoro.Core/Contracts/IViewService.cs @@ -9,4 +9,5 @@ public interface IViewService Task SelectModel(IEnumerable models) where T : class; Task SubmitTimeStamp(long malId, int ep, VideoStream stream, double duration, double introStart); Task Question(string title, string message); + Task Information(string title, string message); } diff --git a/Totoro.Core/Services/WindowsUpdateService.cs b/Totoro.Core/Services/WindowsUpdateService.cs index 7a2a3089..97ac1c78 100644 --- a/Totoro.Core/Services/WindowsUpdateService.cs +++ b/Totoro.Core/Services/WindowsUpdateService.cs @@ -5,10 +5,13 @@ namespace Totoro.Core.Services; -public class WindowsUpdateService : IUpdateService, IEnableLogger +public class WindowsUpdateService : ReactiveObject, IUpdateService, IEnableLogger { private readonly IObservable _onUpdate; private readonly string _updateFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Totoro", "ApplicationData", "Updates"); + private readonly HttpClient _httpClient; + private VersionInfo _current; + public IObservable OnUpdateAvailable => _onUpdate; public WindowsUpdateService(HttpClient httpClient) @@ -21,15 +24,34 @@ public WindowsUpdateService(HttpClient httpClient) .Select(jsonNode => new VersionInfo() { Version = new Version(jsonNode["tag_name"].ToString()), - Url = (string)jsonNode["assets"][0]["browser_download_url"].AsValue() + Url = (string)jsonNode["assets"][0]["browser_download_url"].AsValue(), + Body = jsonNode?["body"]?.ToString() }) -#if !DEBUG .Where(vi => vi.Version > Assembly.GetEntryAssembly().GetName().Version) -#else - .Where(vi => false) -#endif .Log(this, "New Version", vi => vi.Version.ToString()) .Throttle(TimeSpan.FromSeconds(3)); + _httpClient = httpClient; + } + + public async ValueTask GetCurrentVersionInfo() + { + if(_current is null) + { + var url = $"https://api.github.com/repositories/522584084/releases/tags/{Assembly.GetEntryAssembly().GetName().Version}"; + var response = await _httpClient.GetAsync(url); + + if(response.IsSuccessStatusCode) + { + var jsonNode = JsonNode.Parse(await response.Content.ReadAsStreamAsync()); + _current = new VersionInfo() + { + Version = new Version(jsonNode["tag_name"].ToString()), + Url = (string)jsonNode["assets"][0]["browser_download_url"].AsValue(), + Body = jsonNode?["body"]?.ToString() + }; + } + } + return _current; } public async Task DownloadUpdate(VersionInfo versionInfo) diff --git a/Totoro.Core/ViewModels/SettingsViewModel.cs b/Totoro.Core/ViewModels/SettingsViewModel.cs index 5297abf3..41132b04 100644 --- a/Totoro.Core/ViewModels/SettingsViewModel.cs +++ b/Totoro.Core/ViewModels/SettingsViewModel.cs @@ -26,11 +26,13 @@ public class SettingsViewModel : NavigatableViewModel, ISettings public List LogLevels { get; } = new List { LogLevel.Debug, LogLevel.Information, LogLevel.Warning, LogLevel.Error, LogLevel.Critical }; public List ServiceTypes { get; } = new List { ListServiceType.MyAnimeList, ListServiceType.AniList }; public ICommand AuthenticateCommand { get; } + public ICommand ShowAbout { get; } public SettingsViewModel(IThemeSelectorService themeSelectorService, ILocalSettingsService localSettingsService, IViewService viewService, - IDiscordRichPresense dRpc) + IDiscordRichPresense dRpc, + IUpdateService updateService) { Version = Assembly.GetEntryAssembly().GetName().Version; ScrapperVersion = typeof(AnimDL.Core.DefaultUrl).Assembly.GetName().Version; @@ -55,6 +57,15 @@ public SettingsViewModel(IThemeSelectorService themeSelectorService, } AuthenticateCommand = ReactiveCommand.CreateFromTask(viewService.Authenticate); + ShowAbout = ReactiveCommand.CreateFromTask(async () => + { + var currentInfo = await updateService.GetCurrentVersionInfo(); + if(currentInfo is null) + { + return; + } + await viewService.Information($"{currentInfo.Version}", currentInfo.Body); + }); if (UseDiscordRichPresense && !dRpc.IsInitialized) { diff --git a/Totoro.WinUI/Services/ViewService.cs b/Totoro.WinUI/Services/ViewService.cs index 880b3462..93b58cd2 100644 --- a/Totoro.WinUI/Services/ViewService.cs +++ b/Totoro.WinUI/Services/ViewService.cs @@ -1,4 +1,5 @@ using AnimDL.Core.Api; +using CommunityToolkit.WinUI.UI.Controls; using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Controls; using Totoro.WinUI.Contracts; @@ -177,4 +178,20 @@ public async Task Question(string title, string message) var result = await dialog.ShowAsync(); return result == ContentDialogResult.Primary; } + + public async Task Information(string title, string message) + { + var dialog = new ContentDialog() + { + Title = title, + Style = Application.Current.Resources["DefaultContentDialogStyle"] as Style, + XamlRoot = App.MainWindow.Content.XamlRoot, + DefaultButton = ContentDialogButton.Primary, + Content = new MarkdownTextBlock() { Text = message, TextWrapping = TextWrapping.WrapWholeWords, Padding = new Thickness(10)}, + PrimaryButtonText = "Yes", + }; + + var result = await dialog.ShowAsync(); + return Unit.Default; + } } diff --git a/Totoro.WinUI/Views/SettingsPage.xaml b/Totoro.WinUI/Views/SettingsPage.xaml index aff59320..2dd99ce1 100644 --- a/Totoro.WinUI/Views/SettingsPage.xaml +++ b/Totoro.WinUI/Views/SettingsPage.xaml @@ -156,8 +156,9 @@ OnContent="On" />