From 61be286d7326f66018b77c060ce437c10fc0c112 Mon Sep 17 00:00:00 2001 From: Daniel Paulino Date: Fri, 8 Mar 2024 19:52:31 -0800 Subject: [PATCH] Moved static method to interface --- src/Nightingale/Handlers/StoreHandler.cs | 11 +-- src/Nightingale/Handlers/UserSettings.cs | 4 +- .../UserControls/EditorControl.xaml.cs | 3 +- .../UserControls/UrlBarControl.xaml.cs | 7 +- src/Nightingale/Utilities/ThemeController.cs | 5 +- .../ViewModels/EnvironmentsViewModel.cs | 13 ++-- .../ViewModels/ImportPostmanViewModel.cs | 22 +++--- .../ViewModels/MainPageViewModel.cs | 49 +++++++------ .../ViewModels/RequestControlViewModel.cs | 23 +++--- .../ViewModels/WorkspaceViewModel.cs | 29 ++++---- src/Nightingale/Views/MainPage2.xaml.cs | 4 +- src/Nightingale/Views/WorkspacePage.xaml.cs | 7 +- .../VisualState/VisualStatePublisher.cs | 71 ++++++++++--------- 13 files changed, 137 insertions(+), 111 deletions(-) diff --git a/src/Nightingale/Handlers/StoreHandler.cs b/src/Nightingale/Handlers/StoreHandler.cs index ad72d8f..98d3cfb 100644 --- a/src/Nightingale/Handlers/StoreHandler.cs +++ b/src/Nightingale/Handlers/StoreHandler.cs @@ -1,4 +1,5 @@ -using Microsoft.Toolkit.Uwp.Connectivity; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Toolkit.Uwp.Connectivity; using Nightingale.Core.Settings; using System; using System.Collections.Generic; @@ -41,12 +42,12 @@ public static async Task> GetLicensesA /// True if user is subscribed or has purchased premium, false otherwise. public static async Task IsUserSubscribed() { - long userSubDateTicks = UserSettings.Get(SettingsConstants.PremiumDateUnlocked); + long userSubDateTicks = App.Services.GetRequiredService().Get(SettingsConstants.PremiumDateUnlocked); DateTime userSubDate = new DateTime(userSubDateTicks); if (userSubDate > DateTime.MinValue) { - string premiumId = UserSettings.Get(SettingsConstants.PremiumIapId); + string premiumId = App.Services.GetRequiredService().Get(SettingsConstants.PremiumIapId); if (premiumId == PremiumDurable) { @@ -129,8 +130,8 @@ public static async Task IsUserSubscribed() private static void UpdateLocalSettings(string iapId, long ticks) { - UserSettings.Set(SettingsConstants.PremiumDateUnlocked, ticks); - UserSettings.Set(SettingsConstants.PremiumIapId, iapId.ToUpper()); + App.Services.GetRequiredService().Set(SettingsConstants.PremiumDateUnlocked, ticks); + App.Services.GetRequiredService().Set(SettingsConstants.PremiumIapId, iapId.ToUpper()); } /// diff --git a/src/Nightingale/Handlers/UserSettings.cs b/src/Nightingale/Handlers/UserSettings.cs index 180d99d..6b60962 100644 --- a/src/Nightingale/Handlers/UserSettings.cs +++ b/src/Nightingale/Handlers/UserSettings.cs @@ -9,12 +9,12 @@ namespace Nightingale.Handlers /// public class UserSettings : IUserSettings { - public static void Set(string settingKey, object value) + public void Set(string settingKey, object value) { ApplicationData.Current.LocalSettings.Values[settingKey] = (T)value; } - public static T Get(string settingKey) + public T Get(string settingKey) { object result = ApplicationData.Current.LocalSettings.Values[settingKey]; return result == null ? (T)SettingsConstants.Defaults[settingKey] : (T)result; diff --git a/src/Nightingale/UserControls/EditorControl.xaml.cs b/src/Nightingale/UserControls/EditorControl.xaml.cs index 5250b95..b4328e8 100644 --- a/src/Nightingale/UserControls/EditorControl.xaml.cs +++ b/src/Nightingale/UserControls/EditorControl.xaml.cs @@ -17,6 +17,7 @@ using System.Linq; using Nightingale.Handlers; using Nightingale.Core.Settings; +using Microsoft.Extensions.DependencyInjection; // The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236 @@ -54,7 +55,7 @@ public EditorControl() Editor.InputBindings.Remove(binding); } - Editor.IsWordWrapEnabled = UserSettings.Get(SettingsConstants.WordWrapEditor); + Editor.IsWordWrapEnabled = App.Services.GetRequiredService().Get(SettingsConstants.WordWrapEditor); } private void ThemeController_ThemeChanged(object sender, EventArgs e) diff --git a/src/Nightingale/UserControls/UrlBarControl.xaml.cs b/src/Nightingale/UserControls/UrlBarControl.xaml.cs index 0d9296b..e6515f7 100644 --- a/src/Nightingale/UserControls/UrlBarControl.xaml.cs +++ b/src/Nightingale/UserControls/UrlBarControl.xaml.cs @@ -1,4 +1,5 @@ -using Nightingale.Core.Settings; +using Microsoft.Extensions.DependencyInjection; +using Nightingale.Core.Settings; using Nightingale.CustomEventArgs; using Nightingale.Handlers; using Nightingale.Utilities; @@ -25,7 +26,7 @@ public UrlBarControl() { this.InitializeComponent(); - if (UserSettings.Get(SettingsConstants.AlwaysWrapURL)) + if (App.Services.GetRequiredService().Get(SettingsConstants.AlwaysWrapURL)) { VisualStateManager.GoToState(this, "Focused", false); } @@ -72,7 +73,7 @@ private void UrlLostFocus() UrlTextBoxLostFocus?.Invoke(this, new EventArgs()); // Only revert to normal if alwaysWrapUrl = true. - if (!UserSettings.Get(SettingsConstants.AlwaysWrapURL)) + if (!App.Services.GetRequiredService().Get(SettingsConstants.AlwaysWrapURL)) { VisualStateManager.GoToState(this, "Normal", false); } diff --git a/src/Nightingale/Utilities/ThemeController.cs b/src/Nightingale/Utilities/ThemeController.cs index 143fadf..6bbfbca 100644 --- a/src/Nightingale/Utilities/ThemeController.cs +++ b/src/Nightingale/Utilities/ThemeController.cs @@ -1,4 +1,5 @@ -using Nightingale.Core.Settings; +using Microsoft.Extensions.DependencyInjection; +using Nightingale.Core.Settings; using Nightingale.CustomEventArgs; using Nightingale.Handlers; using System; @@ -25,7 +26,7 @@ public static void ChangeTheme(SelectedTheme selectedTheme) public static void ChangeBackgroundImage(string imageName) { - UserSettings.Set(SettingsConstants.BackgroundImage, imageName); + App.Services.GetRequiredService().Set(SettingsConstants.BackgroundImage, imageName); BackgroundImageChanged?.Invoke(new ThemeController(), new AddedItemArgs(imageName)); } } diff --git a/src/Nightingale/ViewModels/EnvironmentsViewModel.cs b/src/Nightingale/ViewModels/EnvironmentsViewModel.cs index cd0aec8..4ae69c8 100644 --- a/src/Nightingale/ViewModels/EnvironmentsViewModel.cs +++ b/src/Nightingale/ViewModels/EnvironmentsViewModel.cs @@ -17,6 +17,7 @@ public class EnvironmentsViewModel : ViewModelBase { private readonly IEnvironmentListModifier _envListModifier; private readonly IParameterStorageAccessor _parameterStorageAccessor; + private readonly IUserSettings _userSettings; private string _newEnvName; private bool _premiumMessageVisible; private bool _addButtonEnabled = true; @@ -24,15 +25,17 @@ public class EnvironmentsViewModel : ViewModelBase public EnvironmentsViewModel( IEnvironmentListModifier listModifier, - IParameterStorageAccessor parameterStorageAccessor) + IParameterStorageAccessor parameterStorageAccessor, + IUserSettings userSettings) { - _envListModifier = listModifier ?? throw new ArgumentNullException(nameof(listModifier)); - _parameterStorageAccessor = parameterStorageAccessor ?? throw new ArgumentNullException(nameof(parameterStorageAccessor)); + _envListModifier = listModifier; + _parameterStorageAccessor = parameterStorageAccessor; + _userSettings = userSettings; } public bool EnvQuickEditOn { - get => UserSettings.Get(SettingsConstants.EnableEnvQuickEdit); + get => _userSettings.Get(SettingsConstants.EnableEnvQuickEdit); set { if (value == EnvQuickEditOn) @@ -40,7 +43,7 @@ public bool EnvQuickEditOn return; } - UserSettings.Set(SettingsConstants.EnableEnvQuickEdit, value); + _userSettings.Set(SettingsConstants.EnableEnvQuickEdit, value); Analytics.TrackEvent("Settings changed: EnableEnvQuickEdit", new Dictionary { { "Value", value ? "true" : "false" }, diff --git a/src/Nightingale/ViewModels/ImportPostmanViewModel.cs b/src/Nightingale/ViewModels/ImportPostmanViewModel.cs index 086fdf4..1b9c4bc 100644 --- a/src/Nightingale/ViewModels/ImportPostmanViewModel.cs +++ b/src/Nightingale/ViewModels/ImportPostmanViewModel.cs @@ -40,6 +40,7 @@ public class ImportPostmanViewModel : ObservableObject private readonly INcfImporter _ncfImporter; private readonly ICurlConverter _curlConverter; private readonly IODataImporter _odataImporter; + private readonly IUserSettings _userSettings; private string _message = ""; public ImportPostmanViewModel( @@ -49,22 +50,23 @@ public ImportPostmanViewModel( INcfImporter ncfImporter, ISwaggerImporter swaggerImporter, IODataImporter odataImporter, - ICurlConverter curlConverter) + ICurlConverter curlConverter, + IUserSettings userSettings) { - _odataImporter = odataImporter ?? throw new ArgumentNullException(nameof(odataImporter)); - _filePicker = filePicker ?? throw new ArgumentNullException(nameof(filePicker)); - _postmanImporter = postmanImporter ?? throw new ArgumentNullException(nameof(postmanImporter)); - _swaggerImporter = swaggerImporter ?? throw new ArgumentNullException(nameof(swaggerImporter)); - _insomniaImporter = insomniaImporter ?? throw new ArgumentNullException(nameof(insomniaImporter)); - _curlConverter = curlConverter ?? throw new ArgumentNullException(nameof(curlConverter)); - _ncfImporter = ncfImporter ?? throw new ArgumentNullException(nameof(ncfImporter)); + _odataImporter = odataImporter; + _filePicker = filePicker; + _postmanImporter = postmanImporter; + _swaggerImporter = swaggerImporter; + _insomniaImporter = insomniaImporter; + _curlConverter = curlConverter; + _ncfImporter = ncfImporter; } public int ImportTypeSelected { get { - int lastTypeUsed = UserSettings.Get(SettingsConstants.LastImportTypeUsed); + int lastTypeUsed = _userSettings.Get(SettingsConstants.LastImportTypeUsed); return Enum.IsDefined(typeof(ImportType), lastTypeUsed) ? lastTypeUsed @@ -74,7 +76,7 @@ public int ImportTypeSelected { if (ImportTypeSelected != value && Enum.IsDefined(typeof(ImportType), value)) { - UserSettings.Set(SettingsConstants.LastImportTypeUsed, value); + _userSettings.Set(SettingsConstants.LastImportTypeUsed, value); OnPropertyChanged(nameof(CurlBoxVisible)); OnPropertyChanged(nameof(DragDropVislble)); } diff --git a/src/Nightingale/ViewModels/MainPageViewModel.cs b/src/Nightingale/ViewModels/MainPageViewModel.cs index 3b99a0c..7939d61 100644 --- a/src/Nightingale/ViewModels/MainPageViewModel.cs +++ b/src/Nightingale/ViewModels/MainPageViewModel.cs @@ -54,6 +54,7 @@ public class MainPageViewModel : ViewModelBase private readonly IDeployService _deployService; private readonly IStorage _storage; private readonly IExportService _exportService; + private readonly IUserSettings _userSettings; private readonly string _workspaceRootId = "root"; private Workspace _selectedWorkspace; private bool _saving; @@ -81,26 +82,28 @@ public MainPageViewModel( IDeployService deployService, MvpViewModel mvpViewModel, IStorage storage, - IExportService exportService) - { - MvpViewModel = mvpViewModel ?? throw new ArgumentNullException(nameof(mvpViewModel)); - _storage = storage ?? throw new ArgumentNullException(nameof(storage)); - _workspaceStorageAccessor = workspaceStorageAccessor ?? throw new ArgumentNullException(nameof(workspaceStorageAccessor)); - _workspaceListModifier = workspaceListModifier ?? throw new ArgumentNullException(nameof(workspaceListModifier)); - _workspaceContainer = workspaceContainer ?? throw new ArgumentNullException(nameof(workspaceContainer)); - _environmentContainer = environmentContainer ?? throw new ArgumentNullException(nameof(environmentContainer)); - _cookieJar = cookieJar ?? throw new ArgumentNullException(nameof(cookieJar)); - _workspaceNavigationService = workspaceNavigationService ?? throw new ArgumentNullException(nameof(workspaceNavigationService)); - _cookieDialogService = cookieDialogService ?? throw new ArgumentNullException(nameof(cookieDialogService)); - _dialogService = dialogService ?? throw new ArgumentNullException(nameof(dialogService)); - _messageBus = messageBus ?? throw new ArgumentNullException(nameof(messageBus)); - _methodsContainer = methodsContainer ?? throw new ArgumentNullException(nameof(methodsContainer)); - _workspaceTreeModifier = workspaceTreeModifier ?? throw new ArgumentNullException(nameof(workspaceTreeModifier)); - _visualStatePublisher = visualStatePublisher ?? throw new ArgumentNullException(nameof(visualStatePublisher)); - _environmentDialogService = environmentDialogService ?? throw new ArgumentNullException(nameof(environmentDialogService)); - _tabContainer = tabContainer ?? throw new ArgumentNullException(nameof(tabContainer)); - _deployService = deployService ?? throw new ArgumentNullException(nameof(deployService)); - _exportService = exportService ?? throw new ArgumentNullException(nameof(exportService)); + IExportService exportService, + IUserSettings userSettings) + { + MvpViewModel = mvpViewModel; + _storage = storage; + _workspaceStorageAccessor = workspaceStorageAccessor; + _workspaceListModifier = workspaceListModifier; + _workspaceContainer = workspaceContainer ; + _environmentContainer = environmentContainer; + _cookieJar = cookieJar; + _workspaceNavigationService = workspaceNavigationService; + _cookieDialogService = cookieDialogService; + _dialogService = dialogService; + _messageBus = messageBus; + _methodsContainer = methodsContainer; + _workspaceTreeModifier = workspaceTreeModifier; + _visualStatePublisher = visualStatePublisher; + _environmentDialogService = environmentDialogService; + _tabContainer = tabContainer; + _deployService = deployService; + _exportService = exportService; + _userSettings = userSettings; this._workspaceItemNavigationService = workspaceItemNavigationService ?? throw new ArgumentNullException(nameof(workspaceItemNavigationService)); UpdateRateButtonVisibility(); @@ -116,7 +119,7 @@ public MainPageViewModel( _visualStatePublisher.PaneLayoutToggled += PaneLayoutChanged; - if (UserSettings.Get(SettingsConstants.AutoSaveInterval)) + if (_userSettings.Get(SettingsConstants.AutoSaveInterval)) { _saveTimer = new Timer(TimerCallback, null, 300000 /* 5 minutes */, 300000); } @@ -174,7 +177,7 @@ private async void MainPageViewModel_CloseRequested(object sender, Windows.UI.Co { var deferral = e.GetDeferral(); - if (UserSettings.Get(SettingsConstants.AutoSaveEnabled)) + if (_userSettings.Get(SettingsConstants.AutoSaveEnabled)) { Saving = true; await _workspaceStorageAccessor.SaveWorkspacesAsync(Workspaces, _workspaceRootId, SelectedWorkspace?.Id); @@ -639,7 +642,7 @@ private async void UpdateRateButtonVisibility() { bool displayRateButton = await Task.Run(() => { - bool IsAlreadyRated = UserSettings.Get(SettingsConstants.IsAppRated); + bool IsAlreadyRated = _userSettings.Get(SettingsConstants.IsAppRated); return IsAlreadyRated ? false : new Random().Next(2) == 0; }); diff --git a/src/Nightingale/ViewModels/RequestControlViewModel.cs b/src/Nightingale/ViewModels/RequestControlViewModel.cs index 554122d..2563564 100644 --- a/src/Nightingale/ViewModels/RequestControlViewModel.cs +++ b/src/Nightingale/ViewModels/RequestControlViewModel.cs @@ -37,6 +37,7 @@ public class RequestControlViewModel : ViewModelBase private readonly IVisualStatePublisher _visualStatePublisher; private readonly IMessageBus _messageBus; private readonly ICurlConverter _curlConverter; + private readonly IUserSettings _userSettings; private readonly ResourceLoader _resourceLoader; private Item _request; @@ -53,17 +54,19 @@ public RequestControlViewModel( IVariableResolver variableResolver, IVisualStatePublisher visualStatePublisher, IMessageBus messageBus, - ICurlConverter curlConverter) + ICurlConverter curlConverter, + IUserSettings userSettings) { _cts = new CancellationTokenSource(); - _requestSender = sender ?? throw new ArgumentNullException(nameof(sender)); - _curlConverter = curlConverter ?? throw new ArgumentNullException(nameof(curlConverter)); - _fileWriter = fileWriter ?? throw new ArgumentNullException(nameof(fileWriter)); - _responseValueExtractor = responseValueExtractor ?? throw new ArgumentNullException(nameof(responseValueExtractor)); - EnvironmentContainer = environmentContainer ?? throw new ArgumentNullException(nameof(environmentContainer)); - _variableResolver = variableResolver ?? throw new ArgumentNullException(nameof(variableResolver)); - _visualStatePublisher = visualStatePublisher ?? throw new ArgumentNullException(nameof(visualStatePublisher)); - _messageBus = messageBus ?? throw new ArgumentNullException(nameof(messageBus)); + _requestSender = sender; + _curlConverter = curlConverter; + _fileWriter = fileWriter; + _responseValueExtractor = responseValueExtractor; + EnvironmentContainer = environmentContainer; + _variableResolver = variableResolver; + _visualStatePublisher = visualStatePublisher; + _messageBus = messageBus; + _userSettings = userSettings; _resourceLoader = ResourceLoader.GetForCurrentView(); _visualStatePublisher.PaneLayoutToggled += VisualStatePublisher_PaneLayoutToggled; @@ -465,7 +468,7 @@ private async Task SendRequest(bool downloadResponse) WorkspaceResponse response = await _requestSender.SendRequestAsync( Request, _cts.Token, - UserSettings.Get(SettingsConstants.HistoryEnabled)); + _userSettings.Get(SettingsConstants.HistoryEnabled)); if (Request is HistoryItem) { diff --git a/src/Nightingale/ViewModels/WorkspaceViewModel.cs b/src/Nightingale/ViewModels/WorkspaceViewModel.cs index 0f3f9ae..17cfa83 100644 --- a/src/Nightingale/ViewModels/WorkspaceViewModel.cs +++ b/src/Nightingale/ViewModels/WorkspaceViewModel.cs @@ -37,6 +37,7 @@ public class WorkspaceViewModel : ViewModelBase private readonly IDeployService _deployService; private readonly KbShortcutsHandler _keyboardShortcutHandler; private readonly IExportService _exportService; + private readonly IUserSettings _userSettings; private Workspace _selectedWorkspace; private bool _exportFlyoutVisible; @@ -49,17 +50,19 @@ public WorkspaceViewModel( ITabCollectionContainer tabContainer, KbShortcutsHandler keyboardShortcutHandler, IDeployService deployService, - IExportService exportService) - { - _exportService = exportService ?? throw new ArgumentNullException(nameof(exportService)); - _workspaceModifier = workspaceModifier ?? throw new ArgumentNullException(nameof(workspaceModifier)); - _visualStatePublisher = visualStatePublisher ?? throw new ArgumentNullException(nameof(visualStatePublisher)); - _environmentDialogService = environmentDialogFactory ?? throw new ArgumentNullException(nameof(environmentDialogFactory)); - _workspaceItemNavigationService = workspaceItemNavigationService ?? throw new ArgumentNullException(nameof(workspaceItemNavigationService)); - _codeGeneratorViewModelFactory = codeGeneratorViewModelFactory ?? throw new ArgumentNullException(nameof(codeGeneratorViewModelFactory)); - _tabContainer = tabContainer ?? throw new ArgumentNullException(nameof(tabContainer)); - _deployService = deployService ?? throw new ArgumentNullException(nameof(deployService)); - _keyboardShortcutHandler = keyboardShortcutHandler ?? throw new ArgumentNullException(nameof(keyboardShortcutHandler)); + IExportService exportService, + IUserSettings userSettings) + { + _exportService = exportService; + _workspaceModifier = workspaceModifier; + _visualStatePublisher = visualStatePublisher; + _environmentDialogService = environmentDialogFactory; + _workspaceItemNavigationService = workspaceItemNavigationService; + _codeGeneratorViewModelFactory = codeGeneratorViewModelFactory; + _tabContainer = tabContainer; + _deployService = deployService; + _keyboardShortcutHandler = keyboardShortcutHandler; + _userSettings = userSettings; _visualStatePublisher.SideBarVisibilityChanged -= _visualStatePublisher_SideBarVisibilityChanged; _visualStatePublisher.SideBarVisibilityChanged += _visualStatePublisher_SideBarVisibilityChanged; @@ -89,7 +92,7 @@ public Workspace SelectedWorkspace public bool IsSideBarVisible { - get => UserSettings.Get(SettingsConstants.SideBarVisible); + get => _userSettings.Get(SettingsConstants.SideBarVisible); set { if (IsSideBarVisible != value) @@ -211,7 +214,7 @@ public GridLength UserSidebarWidth { get { - double widthValue = IsSideBarVisible ? UserSettings.Get(SettingsConstants.SidebarWidth) : 0d; + double widthValue = IsSideBarVisible ? _userSettings.Get(SettingsConstants.SidebarWidth) : 0d; return new GridLength(widthValue, GridUnitType.Pixel); } } diff --git a/src/Nightingale/Views/MainPage2.xaml.cs b/src/Nightingale/Views/MainPage2.xaml.cs index 70648ef..eacf869 100644 --- a/src/Nightingale/Views/MainPage2.xaml.cs +++ b/src/Nightingale/Views/MainPage2.xaml.cs @@ -52,7 +52,7 @@ public MainPage2() private void ChangeBackgroundImageTheme(object sender, EventArgs e) { - var imageName = UserSettings.Get(SettingsConstants.BackgroundImage); + var imageName = App.Services.GetRequiredService().Get(SettingsConstants.BackgroundImage); if (!string.IsNullOrWhiteSpace(imageName)) { var isDarkTheme = App.RootFrame.ActualTheme == ElementTheme.Dark; @@ -71,7 +71,7 @@ private void ChangeBackground(object sender, CustomEventArgs.AddedItemArgs(SettingsConstants.BackgroundImage); + var imageName = App.Services.GetRequiredService().Get(SettingsConstants.BackgroundImage); SetBackground(imageName); } diff --git a/src/Nightingale/Views/WorkspacePage.xaml.cs b/src/Nightingale/Views/WorkspacePage.xaml.cs index cf3e1b9..b2fc7bc 100644 --- a/src/Nightingale/Views/WorkspacePage.xaml.cs +++ b/src/Nightingale/Views/WorkspacePage.xaml.cs @@ -1,4 +1,5 @@ -using Nightingale.Core.Settings; +using Microsoft.Extensions.DependencyInjection; +using Nightingale.Core.Settings; using Nightingale.Core.Workspaces.Models; using Nightingale.Handlers; using Nightingale.Navigation; @@ -60,7 +61,7 @@ private void Grid_SizeChanged(object sender, SizeChangedEventArgs e) var inputWidth = SideBarColumn.Width.Value; if (!double.IsNaN(inputWidth)) { - UserSettings.Set(SettingsConstants.SidebarWidth, inputWidth); + App.Services.GetRequiredService().Set(SettingsConstants.SidebarWidth, inputWidth); } } } @@ -142,7 +143,7 @@ private void MainGridSizeChanged(object sender, SizeChangedEventArgs e) private void EnvQuickEditClicked(object sender, RoutedEventArgs e) { - if (UserSettings.Get(SettingsConstants.EnableEnvQuickEdit)) + if (App.Services.GetRequiredService().Get(SettingsConstants.EnableEnvQuickEdit)) { if (sender is FrameworkElement fe) { diff --git a/src/Nightingale/VisualState/VisualStatePublisher.cs b/src/Nightingale/VisualState/VisualStatePublisher.cs index 643e8ae..112e83a 100644 --- a/src/Nightingale/VisualState/VisualStatePublisher.cs +++ b/src/Nightingale/VisualState/VisualStatePublisher.cs @@ -2,47 +2,54 @@ using Nightingale.Handlers; using System; -namespace Nightingale.VisualState +#nullable enable + +namespace Nightingale.VisualState; + +public class VisualStatePublisher : IVisualStatePublisher { - public class VisualStatePublisher : IVisualStatePublisher + private readonly IUserSettings _userSettings; + private bool _tempLayoutSinglePane = false; + + public event EventHandler? SideBarVisibilityChanged; + public event EventHandler? PaneLayoutToggled; + + public VisualStatePublisher(IUserSettings userSettings) { - public event EventHandler SideBarVisibilityChanged; - public event EventHandler PaneLayoutToggled; + _userSettings = userSettings; + } - private bool _tempLayoutSinglePane = false; + /// + public bool GetSideBarVisibility() + { + return _userSettings.Get(SettingsConstants.SideBarVisible); + } - /// - public bool GetSideBarVisibility() - { - return UserSettings.Get(SettingsConstants.SideBarVisible); - } + public void SetSideBarVisibility(bool value) + { + _userSettings.Set(SettingsConstants.SideBarVisible, value); + SideBarVisibilityChanged?.Invoke(this, new EventArgs()); + } - public void SetSideBarVisibility(bool value) - { - UserSettings.Set(SettingsConstants.SideBarVisible, value); - SideBarVisibilityChanged?.Invoke(this, new EventArgs()); - } + public void SetPaneLayoutSideBySide(bool value) + { + _userSettings.Set(SettingsConstants.PaneLayoutSideBySide, value); + PaneLayoutToggled?.Invoke(this, new EventArgs()); + } - public void SetPaneLayoutSideBySide(bool value) - { - UserSettings.Set(SettingsConstants.PaneLayoutSideBySide, value); - PaneLayoutToggled?.Invoke(this, new EventArgs()); - } + public void SetTempSinglePane(bool value) + { + _tempLayoutSinglePane = value; + PaneLayoutToggled?.Invoke(this, new EventArgs()); + } - public void SetTempSinglePane(bool value) + public bool IsLayoutTwoPane() + { + if (_tempLayoutSinglePane) { - _tempLayoutSinglePane = value; - PaneLayoutToggled?.Invoke(this, new EventArgs()); + return false; } - public bool IsLayoutTwoPane() - { - if (_tempLayoutSinglePane) - { - return false; - } - - return UserSettings.Get(SettingsConstants.PaneLayoutSideBySide); - } + return _userSettings.Get(SettingsConstants.PaneLayoutSideBySide); } }