mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 03:07:04 +02:00
Remove ISettingsUtils and ISettingsPath interfaces (#44331)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request This PR removes the ISettingsUtils and ISettingsPath interfaces to reduce some complexity. They only existed so the classes can be used with moq. But this is also possible by using virtual methods which is cleaner. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [ ] Closes: #xxx <!-- - [ ] Closes: #yyy (add separate lines for additional resolved issues) --> - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Abstractions;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
|
||||
using ManagedCommon;
|
||||
@@ -14,12 +15,13 @@ using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
public class SettingsUtils : ISettingsUtils
|
||||
// Some functions are marked as virtual to allow mocking in unit tests.
|
||||
public class SettingsUtils
|
||||
{
|
||||
public const string DefaultFileName = "settings.json";
|
||||
private const string DefaultModuleName = "";
|
||||
private readonly IFile _file;
|
||||
private readonly ISettingsPath _settingsPath;
|
||||
private readonly SettingPath _settingsPath;
|
||||
private readonly JsonSerializerOptions _serializerOptions;
|
||||
|
||||
/// <summary>
|
||||
@@ -39,7 +41,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
{
|
||||
}
|
||||
|
||||
public SettingsUtils(IFile file, ISettingsPath settingPath, JsonSerializerOptions? serializerOptions = null)
|
||||
public SettingsUtils(IFile file, SettingPath settingPath, JsonSerializerOptions? serializerOptions = null)
|
||||
{
|
||||
_file = file ?? throw new ArgumentNullException(nameof(file));
|
||||
_settingsPath = settingPath;
|
||||
@@ -62,7 +64,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
_settingsPath.DeleteSettings(powertoy);
|
||||
}
|
||||
|
||||
public T GetSettings<T>(string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
public virtual T GetSettings<T>(string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
where T : ISettingsConfig, new()
|
||||
{
|
||||
if (!SettingsExists(powertoy, fileName))
|
||||
@@ -87,7 +89,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
/// This function creates a file in the powertoy folder if it does not exist and returns an object with default properties.
|
||||
/// </summary>
|
||||
/// <returns>Deserialized json settings object.</returns>
|
||||
public T GetSettingsOrDefault<T>(string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
public virtual T GetSettingsOrDefault<T>(string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
where T : ISettingsConfig, new()
|
||||
{
|
||||
try
|
||||
@@ -118,7 +120,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
/// This function creates a file in the powertoy folder if it does not exist and returns an object with default properties.
|
||||
/// </summary>
|
||||
/// <returns>Deserialized json settings object.</returns>
|
||||
public T GetSettingsOrDefault<T, T2>(string powertoy = DefaultModuleName, string fileName = DefaultFileName, Func<object, object>? settingsUpgrader = null)
|
||||
public virtual T GetSettingsOrDefault<T, T2>(string powertoy = DefaultModuleName, string fileName = DefaultFileName, Func<object, object>? settingsUpgrader = null)
|
||||
where T : ISettingsConfig, new()
|
||||
where T2 : ISettingsConfig, new()
|
||||
{
|
||||
@@ -203,7 +205,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library
|
||||
}
|
||||
|
||||
// Save settings to a json file.
|
||||
public void SaveSettings(string jsonSettings, string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
public virtual void SaveSettings(string jsonSettings, string powertoy = DefaultModuleName, string fileName = DefaultFileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user