From 787313597fc406d1b3932109d242b5d7ed153bc2 Mon Sep 17 00:00:00 2001 From: sar Date: Sun, 12 Mar 2023 04:29:03 +0100 Subject: [PATCH 01/14] reducing file io by no longer reloading from persistent storage during runtime --- .../Steam/Local/Storage/SteamApiKeyStorage.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/SteamAccountManager.Infrastructure/Steam/Local/Storage/SteamApiKeyStorage.cs b/SteamAccountManager.Infrastructure/Steam/Local/Storage/SteamApiKeyStorage.cs index a8d7ce9..5897f91 100644 --- a/SteamAccountManager.Infrastructure/Steam/Local/Storage/SteamApiKeyStorage.cs +++ b/SteamAccountManager.Infrastructure/Steam/Local/Storage/SteamApiKeyStorage.cs @@ -18,6 +18,7 @@ public SteamApiKeyStorage(ILogger logger) { _apiKeyStorage = new(); _logger = logger; + Load(); } // TODO: throw custom exceptions @@ -26,11 +27,9 @@ private void Load() { try { - using (var streamReader = new StreamReader(FileName)) - { - var json = streamReader.ReadToEnd(); - _apiKeyStorage = JsonConvert.DeserializeObject(json) ?? _apiKeyStorage; - } + using var streamReader = new StreamReader(FileName); + var json = streamReader.ReadToEnd(); + _apiKeyStorage = JsonConvert.DeserializeObject(json) ?? _apiKeyStorage; } catch (FileNotFoundException e) { @@ -58,7 +57,6 @@ private void Save() public string Get() { - Load(); return _apiKeyStorage.Key; } From c8f475b1354b85657e3722afbec9742bee969ffb Mon Sep 17 00:00:00 2001 From: sar Date: Sun, 12 Mar 2023 04:29:48 +0100 Subject: [PATCH 02/14] extended settings tab to show toggles for account details --- .../Dependencies.cs | 7 +- .../Models/Account.cs | 30 ++----- .../SteamAccountSwitcherStyles.xaml | 68 ++++++++-------- .../ViewModels/SettingsViewModel.cs | 79 ++++++++++++++++++- .../Views/SettingsView.axaml | 16 +++- .../Dependencies.cs | 12 +-- .../Steam/Local/Storage/ObjectStorage.cs | 49 ++++++++++++ .../Local/Storage/PrivacyConfigStorage.cs | 42 ++++++++++ 8 files changed, 236 insertions(+), 67 deletions(-) create mode 100644 SteamAccountManager.Infrastructure/Steam/Local/Storage/ObjectStorage.cs create mode 100644 SteamAccountManager.Infrastructure/Steam/Local/Storage/PrivacyConfigStorage.cs diff --git a/SteamAccountManager.AvaloniaUI/Dependencies.cs b/SteamAccountManager.AvaloniaUI/Dependencies.cs index 887f239..1b3729f 100644 --- a/SteamAccountManager.AvaloniaUI/Dependencies.cs +++ b/SteamAccountManager.AvaloniaUI/Dependencies.cs @@ -1,5 +1,4 @@ using Autofac; -using Autofac.Core; using DI; using ReactiveUI; using SteamAccountManager.Application.Steam.Service; @@ -37,15 +36,15 @@ public static void RegisterAvaloniaModule(this ContainerBuilder builder) public static void RegisterViewModels(this ContainerBuilder builder) { - builder.RegisterViewModel(); builder.RegisterViewModel(); } - private static void RegisterViewModel(this ContainerBuilder builder) where ViewModel : RoutableViewModel + private static void RegisterViewModel(this ContainerBuilder builder) + where ViewModel : RoutableViewModel { builder.RegisterType() .WithParameter(new TypedParameter(typeof(IScreen), "screen")); } } -} +} \ No newline at end of file diff --git a/SteamAccountManager.AvaloniaUI/Models/Account.cs b/SteamAccountManager.AvaloniaUI/Models/Account.cs index 32c8dd3..58d1995 100644 --- a/SteamAccountManager.AvaloniaUI/Models/Account.cs +++ b/SteamAccountManager.AvaloniaUI/Models/Account.cs @@ -1,11 +1,9 @@ -using Avalonia.Media.Imaging; -using System; -using System.ComponentModel; -using System.Runtime.CompilerServices; +using System; +using Avalonia.Media.Imaging; namespace SteamAccountManager.AvaloniaUI.Models { - public class Account : INotifyPropertyChanged + public class Account { public IBitmap? ProfilePicture { get; set; } public Uri? ProfilePictureUrl { get; set; } @@ -16,29 +14,15 @@ public class Account : INotifyPropertyChanged public bool IsVacBanned { get; set; } public bool IsCommunityBanned { get; set; } public string LastLogin { get; set; } = string.Empty; - public Rank Rank { get; set; } = new Rank() + + public Rank Rank { get; set; } = new() { Level = -1 }; + public bool ShowLevel { get { return Rank.Level >= 0; } } - - -#pragma warning disable CS8612 // Die NULL-Zulässigkeit von Verweistypen im Typ entspricht nicht dem implizit implementierten Member. - public event PropertyChangedEventHandler PropertyChanged; -#pragma warning restore CS8612 // Die NULL-Zulässigkeit von Verweistypen im Typ entspricht nicht dem implizit implementierten Member. - - // This method is called by the Set accessor of each property. - // The CallerMemberName attribute that is applied to the optional propertyName - // parameter causes the property name of the caller to be substituted as an argument. - private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") - { - if (PropertyChanged != null) - { - PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); - } - } } -} +} \ No newline at end of file diff --git a/SteamAccountManager.AvaloniaUI/SteamAccountSwitcherStyles.xaml b/SteamAccountManager.AvaloniaUI/SteamAccountSwitcherStyles.xaml index de89a3b..e64520e 100644 --- a/SteamAccountManager.AvaloniaUI/SteamAccountSwitcherStyles.xaml +++ b/SteamAccountManager.AvaloniaUI/SteamAccountSwitcherStyles.xaml @@ -1,35 +1,41 @@  - + - - + + - - - + + + + + \ No newline at end of file diff --git a/SteamAccountManager.AvaloniaUI/ViewModels/SettingsViewModel.cs b/SteamAccountManager.AvaloniaUI/ViewModels/SettingsViewModel.cs index c50de03..54093a3 100644 --- a/SteamAccountManager.AvaloniaUI/ViewModels/SettingsViewModel.cs +++ b/SteamAccountManager.AvaloniaUI/ViewModels/SettingsViewModel.cs @@ -1,27 +1,102 @@ -using System.Windows.Input; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Input; +using DynamicData; using ReactiveUI; +using SteamAccountManager.AvaloniaUI.Common; using SteamAccountManager.Infrastructure.Steam.Local.Storage; namespace SteamAccountManager.AvaloniaUI.ViewModels { + public class AccountDetailToggle + { + public string Title { get; set; } + public ICommand ToggledCommand { get; set; } + public bool IsToggled { get; set; } + + public AccountDetailType DetailType { get; set; } + + public AccountDetailToggle(AccountDetailType detailType, string title, ICommand toggledCommand, bool isToggled) + { + Title = title; + ToggledCommand = toggledCommand; + IsToggled = isToggled; + DetailType = detailType; + } + } + public class SettingsViewModel : RoutableViewModel { private readonly SteamApiKeyStorage _steamApiKeyStorage; + private readonly PrivacyConfigStorage _privacyConfigStorage; + + + public AdvancedObservableCollection AccountDetailsToggles { get; } = new(); public ICommand SaveApiKeyCommand { get; } public string WebApiKey { get; set; } - public SettingsViewModel(IScreen screen, SteamApiKeyStorage apiKeyStorage) : base(screen) + public SettingsViewModel + ( + IScreen screen, + SteamApiKeyStorage apiKeyStorage, + PrivacyConfigStorage privacyConfigStorage + ) : base(screen) { _steamApiKeyStorage = apiKeyStorage; + _privacyConfigStorage = privacyConfigStorage; SaveApiKeyCommand = ReactiveCommand.Create((string key) => SaveApiKey(key)); + CreateAccountDetailToggles(); PrefillFields(); } + private void CreateAccountDetailToggles() + { + var detailToggledCommand = + ReactiveCommand.Create((AccountDetailToggle detailToggle) => DetailToggled(detailToggle)); + + AccountDetailsToggles.SetItems + ( + new List + { + new(AccountDetailType.LoginName, title: "Login Name", detailToggledCommand, isToggled: true), + new(AccountDetailType.Username, title: "Username", detailToggledCommand, isToggled: true), + new(AccountDetailType.Level, title: "Level", detailToggledCommand, isToggled: true), + new(AccountDetailType.Avatar, title: "Avatar", detailToggledCommand, isToggled: true), + new(AccountDetailType.BanStatus, title: "Ban Status", detailToggledCommand, isToggled: true), + } + ); + } + + private void DetailToggled(AccountDetailToggle detailToggle) + { + var privacyConfig = _privacyConfigStorage.Get()?.DetailSettings; + if (privacyConfig is not null) + { + var setting = privacyConfig.FirstOrDefault(x => x.DetailType == detailToggle.DetailType); + privacyConfig.ReplaceOrAdd(setting, new DetailSetting(detailToggle.DetailType, detailToggle.IsToggled)); + } + else + { + var settings = AccountDetailsToggles.Select(x => new DetailSetting(x.DetailType, x.IsToggled)); + _privacyConfigStorage.Set(new PrivacyConfig(settings.ToList())); + } + } + private void PrefillFields() { WebApiKey = _steamApiKeyStorage.Get(); + + var privacyConfig = _privacyConfigStorage.Get()?.DetailSettings; + if (privacyConfig is not null) + { + foreach (var toggle in AccountDetailsToggles) + { + toggle.IsToggled = privacyConfig + .FirstOrDefault(x => x.DetailType == toggle.DetailType)?.IsEnabled ?? false; + } + } } private void SaveApiKey(string key) diff --git a/SteamAccountManager.AvaloniaUI/Views/SettingsView.axaml b/SteamAccountManager.AvaloniaUI/Views/SettingsView.axaml index fb5fcdd..3192b2e 100644 --- a/SteamAccountManager.AvaloniaUI/Views/SettingsView.axaml +++ b/SteamAccountManager.AvaloniaUI/Views/SettingsView.axaml @@ -15,9 +15,21 @@ + + + + + + + + + +