From 0acf1ee24ba7716066cc22cd30c4ccf77494100d Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Sat, 28 Sep 2024 00:26:13 +0100 Subject: [PATCH] Show one-off supporters on supporters info page --- Bloxstrap/Extensions/RegistryKeyEx.cs | 2 +- Bloxstrap/Models/APIs/Config/SupporterData.cs | 8 +- .../Models/APIs/Config/SupporterGroup.cs | 11 ++ Bloxstrap/Resources/Strings.Designer.cs | 18 +++ Bloxstrap/Resources/Strings.resx | 6 + Bloxstrap/UI/Elements/About/MainWindow.xaml | 1 + .../UI/Elements/About/Pages/AboutPage.xaml | 80 ----------- .../Elements/About/Pages/SupportersPage.xaml | 131 ++++++++++++++++++ .../About/Pages/SupportersPage.xaml.cs | 16 +++ .../UI/ViewModels/About/AboutViewModel.cs | 46 ------ .../ViewModels/About/SupportersViewModel.cs | 46 ++++++ 11 files changed, 234 insertions(+), 131 deletions(-) create mode 100644 Bloxstrap/Models/APIs/Config/SupporterGroup.cs create mode 100644 Bloxstrap/UI/Elements/About/Pages/SupportersPage.xaml create mode 100644 Bloxstrap/UI/Elements/About/Pages/SupportersPage.xaml.cs create mode 100644 Bloxstrap/UI/ViewModels/About/SupportersViewModel.cs diff --git a/Bloxstrap/Extensions/RegistryKeyEx.cs b/Bloxstrap/Extensions/RegistryKeyEx.cs index a5e9af4f..dd556909 100644 --- a/Bloxstrap/Extensions/RegistryKeyEx.cs +++ b/Bloxstrap/Extensions/RegistryKeyEx.cs @@ -14,7 +14,7 @@ public static void SetValueSafe(this RegistryKey registryKey, string? name, obje catch (UnauthorizedAccessException) { Frontend.ShowMessageBox(Strings.Dialog_RegistryWriteError, System.Windows.MessageBoxImage.Error); - App.Terminate(); + App.Terminate(ErrorCode.ERROR_INSTALL_FAILURE); } } } diff --git a/Bloxstrap/Models/APIs/Config/SupporterData.cs b/Bloxstrap/Models/APIs/Config/SupporterData.cs index 35feb1e9..6a5e37f4 100644 --- a/Bloxstrap/Models/APIs/Config/SupporterData.cs +++ b/Bloxstrap/Models/APIs/Config/SupporterData.cs @@ -2,10 +2,10 @@ { public class SupporterData { - [JsonPropertyName("columns")] - public int Columns { get; set; } + [JsonPropertyName("monthly")] + public SupporterGroup Monthly { get; set; } = new(); - [JsonPropertyName("supporters")] - public List Supporters { get; set; } = null!; + [JsonPropertyName("oneoff")] + public SupporterGroup OneOff { get; set; } = new(); } } diff --git a/Bloxstrap/Models/APIs/Config/SupporterGroup.cs b/Bloxstrap/Models/APIs/Config/SupporterGroup.cs new file mode 100644 index 00000000..822c8edc --- /dev/null +++ b/Bloxstrap/Models/APIs/Config/SupporterGroup.cs @@ -0,0 +1,11 @@ +namespace Bloxstrap.Models.APIs.Config +{ + public class SupporterGroup + { + [JsonPropertyName("columns")] + public int Columns { get; set; } = 0; + + [JsonPropertyName("supporters")] + public List Supporters { get; set; } = Enumerable.Empty().ToList(); + } +} diff --git a/Bloxstrap/Resources/Strings.Designer.cs b/Bloxstrap/Resources/Strings.Designer.cs index 82d3c72c..c0f1bce4 100644 --- a/Bloxstrap/Resources/Strings.Designer.cs +++ b/Bloxstrap/Resources/Strings.Designer.cs @@ -78,6 +78,24 @@ public static string About_Supporters_Description { } } + /// + /// Looks up a localized string similar to Monthly. + /// + public static string About_Supporters_Monthly { + get { + return ResourceManager.GetString("About.Supporters.Monthly", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to One-off. + /// + public static string About_Supporters_OneOff { + get { + return ResourceManager.GetString("About.Supporters.OneOff", resourceCulture); + } + } + /// /// Looks up a localized string similar to Supporters. /// diff --git a/Bloxstrap/Resources/Strings.resx b/Bloxstrap/Resources/Strings.resx index 6ae94863..76d30117 100644 --- a/Bloxstrap/Resources/Strings.resx +++ b/Bloxstrap/Resources/Strings.resx @@ -1207,4 +1207,10 @@ Please manually delete Bloxstrap.exe from the install location or try restarting Bloxstrap is unable to write to the Windows Registry. An antivirus is likely interfering and causing issues. Please check to make sure there isn't anything that would restrict Bloxstrap's operation. + + Monthly + + + One-off + \ No newline at end of file diff --git a/Bloxstrap/UI/Elements/About/MainWindow.xaml b/Bloxstrap/UI/Elements/About/MainWindow.xaml index a334f3a5..5fd1d53d 100644 --- a/Bloxstrap/UI/Elements/About/MainWindow.xaml +++ b/Bloxstrap/UI/Elements/About/MainWindow.xaml @@ -37,6 +37,7 @@ + diff --git a/Bloxstrap/UI/Elements/About/Pages/AboutPage.xaml b/Bloxstrap/UI/Elements/About/Pages/AboutPage.xaml index 0fdccb29..d35d6bf8 100644 --- a/Bloxstrap/UI/Elements/About/Pages/AboutPage.xaml +++ b/Bloxstrap/UI/Elements/About/Pages/AboutPage.xaml @@ -3,7 +3,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:enums="clr-namespace:Bloxstrap.Enums" xmlns:models="clr-namespace:Bloxstrap.UI.ViewModels" xmlns:dmodels="clr-namespace:Bloxstrap.UI.ViewModels.About" xmlns:controls="clr-namespace:Bloxstrap.UI.Elements.Controls" @@ -81,85 +80,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Bloxstrap/UI/Elements/About/Pages/SupportersPage.xaml b/Bloxstrap/UI/Elements/About/Pages/SupportersPage.xaml new file mode 100644 index 00000000..925a5204 --- /dev/null +++ b/Bloxstrap/UI/Elements/About/Pages/SupportersPage.xaml @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Bloxstrap/UI/Elements/About/Pages/SupportersPage.xaml.cs b/Bloxstrap/UI/Elements/About/Pages/SupportersPage.xaml.cs new file mode 100644 index 00000000..c8245584 --- /dev/null +++ b/Bloxstrap/UI/Elements/About/Pages/SupportersPage.xaml.cs @@ -0,0 +1,16 @@ +using Bloxstrap.UI.ViewModels.About; + +namespace Bloxstrap.UI.Elements.About.Pages +{ + /// + /// Interaction logic for SupportersPage.xaml + /// + public partial class SupportersPage + { + public SupportersPage() + { + DataContext = new SupportersViewModel(); + InitializeComponent(); + } + } +} diff --git a/Bloxstrap/UI/ViewModels/About/AboutViewModel.cs b/Bloxstrap/UI/ViewModels/About/AboutViewModel.cs index 6eda400e..8e7177c4 100644 --- a/Bloxstrap/UI/ViewModels/About/AboutViewModel.cs +++ b/Bloxstrap/UI/ViewModels/About/AboutViewModel.cs @@ -4,8 +4,6 @@ namespace Bloxstrap.UI.ViewModels.About { public class AboutViewModel : NotifyPropertyChangedViewModel { - private SupporterData? _supporterData; - public string Version => string.Format(Strings.Menu_About_Version, App.Version); public BuildMetadataAttribute BuildMetadata => App.BuildMetadata; @@ -15,49 +13,5 @@ public class AboutViewModel : NotifyPropertyChangedViewModel public Visibility BuildInformationVisibility => App.IsProductionBuild ? Visibility.Collapsed : Visibility.Visible; public Visibility BuildCommitVisibility => App.IsActionBuild ? Visibility.Visible : Visibility.Collapsed; - - public List Supporters => _supporterData?.Supporters ?? Enumerable.Empty().ToList(); - - public int SupporterColumns => _supporterData?.Columns ?? 0; - - public GenericTriState SupportersLoadedState { get; set; } = GenericTriState.Unknown; - - public string SupportersLoadError { get; set; } = ""; - - public AboutViewModel() - { - // this will cause momentary freezes only when ran under the debugger - LoadSupporterData(); - } - - public async void LoadSupporterData() - { - const string LOG_IDENT = "AboutViewModel::LoadSupporterData"; - - try - { - _supporterData = await Http.GetJson("https://raw.githubusercontent.com/bloxstraplabs/config/main/supporters.json"); - } - catch (Exception ex) - { - App.Logger.WriteLine(LOG_IDENT, "Could not load supporter data"); - App.Logger.WriteException(LOG_IDENT, ex); - - SupportersLoadedState = GenericTriState.Failed; - SupportersLoadError = ex.Message; - - OnPropertyChanged(nameof(SupportersLoadError)); - } - - if (_supporterData is not null) - { - SupportersLoadedState = GenericTriState.Successful; - - OnPropertyChanged(nameof(Supporters)); - OnPropertyChanged(nameof(SupporterColumns)); - } - - OnPropertyChanged(nameof(SupportersLoadedState)); - } } } diff --git a/Bloxstrap/UI/ViewModels/About/SupportersViewModel.cs b/Bloxstrap/UI/ViewModels/About/SupportersViewModel.cs new file mode 100644 index 00000000..cc5afbc6 --- /dev/null +++ b/Bloxstrap/UI/ViewModels/About/SupportersViewModel.cs @@ -0,0 +1,46 @@ +namespace Bloxstrap.UI.ViewModels.About +{ + public class SupportersViewModel : NotifyPropertyChangedViewModel + { + public SupporterData? SupporterData { get; private set; } + + public GenericTriState LoadedState { get; set; } = GenericTriState.Unknown; + + public string LoadError { get; set; } = ""; + + public SupportersViewModel() + { + // this will cause momentary freezes only when ran under the debugger + LoadSupporterData(); + } + + public async void LoadSupporterData() + { + const string LOG_IDENT = "AboutViewModel::LoadSupporterData"; + + try + { + SupporterData = await Http.GetJson("https://raw.githubusercontent.com/bloxstraplabs/config/main/supporters.json"); + } + catch (Exception ex) + { + App.Logger.WriteLine(LOG_IDENT, "Could not load supporter data"); + App.Logger.WriteException(LOG_IDENT, ex); + + LoadedState = GenericTriState.Failed; + LoadError = ex.Message; + + OnPropertyChanged(nameof(LoadError)); + } + + if (SupporterData is not null) + { + LoadedState = GenericTriState.Successful; + + OnPropertyChanged(nameof(SupporterData)); + } + + OnPropertyChanged(nameof(LoadedState)); + } + } +}