Fix settings changes that were made in PR #6620 (#6817)

* validated that restart elevated and check for updates work.Removed isettingsUtils and reused settings repository

* reverted the name to ImageResizer instead of using ImageResizerSettings.Modulename to make it backward compatible
This commit is contained in:
Alekhya
2020-09-24 10:50:49 -07:00
committed by GitHub
parent 8d934df0c0
commit c941b5333c
5 changed files with 8 additions and 19 deletions

View File

@@ -15,8 +15,6 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
{
private GeneralSettings GeneralSettingsConfig { get; set; }
private readonly ISettingsUtils _settingsUtils;
public ButtonClickCommand CheckFoUpdatesEventHandler { get; set; }
public ButtonClickCommand RestartElevatedButtonEventHandler { get; set; }
@@ -35,11 +33,10 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
private string _settingsConfigFileFolder = string.Empty;
public GeneralViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, string runAsAdminText, string runAsUserText, bool isElevated, bool isAdmin, Func<string, int> updateTheme, Func<string, int> ipcMSGCallBackFunc, Func<string, int> ipcMSGRestartAsAdminMSGCallBackFunc, Func<string, int> ipcMSGCheckForUpdatesCallBackFunc, string configFileSubfolder = "")
public GeneralViewModel(ISettingsRepository<GeneralSettings> settingsRepository, string runAsAdminText, string runAsUserText, bool isElevated, bool isAdmin, Func<string, int> updateTheme, Func<string, int> ipcMSGCallBackFunc, Func<string, int> ipcMSGRestartAsAdminMSGCallBackFunc, Func<string, int> ipcMSGCheckForUpdatesCallBackFunc, string configFileSubfolder = "")
{
CheckFoUpdatesEventHandler = new ButtonClickCommand(CheckForUpdates_Click);
RestartElevatedButtonEventHandler = new ButtonClickCommand(Restart_Elevated);
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
// To obtain the general settings configuration of PowerToys if it exists, else to create a new file and return the default configurations.
GeneralSettingsConfig = settingsRepository.SettingsConfig;
@@ -344,10 +341,9 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
// callback function to launch the URL to check for updates.
private void CheckForUpdates_Click()
{
GeneralSettings settings = _settingsUtils.GetSettings<GeneralSettings>(_settingsConfigFileFolder);
settings.CustomActionName = "check_for_updates";
GeneralSettingsConfig.CustomActionName = "check_for_updates";
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings);
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings);
SendCheckForUpdatesConfigMSG(customaction.ToString());
@@ -355,10 +351,9 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
public void Restart_Elevated()
{
GeneralSettings settings = _settingsUtils.GetSettings<GeneralSettings>(_settingsConfigFileFolder);
settings.CustomActionName = "restart_elevation";
GeneralSettingsConfig.CustomActionName = "restart_elevation";
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(settings);
OutGoingGeneralSettings outsettings = new OutGoingGeneralSettings(GeneralSettingsConfig);
GeneralSettingsCustomAction customaction = new GeneralSettingsCustomAction(outsettings);
SendRestartAsAdminConfigMSG(customaction.ToString());

View File

@@ -19,7 +19,8 @@ namespace Microsoft.PowerToys.Settings.UI.Lib.ViewModels
private ImageResizerSettings Settings { get; set; }
private const string ModuleName = ImageResizerSettings.ModuleName;
// NOTE: Not using ImageResizerSettings.ModuleName ("Image Resizer") to be backward compatible.
private const string ModuleName = "ImageResizer";
private Func<string, int> SendConfigMSG { get; }

View File

@@ -35,7 +35,6 @@ namespace ViewModelTests
Func<string, int> SendRestartAdminIPCMessage = msg => { return 0; };
Func<string, int> SendCheckForUpdatesIPCMessage = msg => { return 0; };
GeneralViewModel viewModel = new GeneralViewModel(
new Mock<ISettingsUtils>().Object,
SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
"GeneralSettings_RunningAsAdminText",
"GeneralSettings_RunningAsUserText",
@@ -73,7 +72,6 @@ namespace ViewModelTests
Func<string, int> SendRestartAdminIPCMessage = msg => { return 0; };
Func<string, int> SendCheckForUpdatesIPCMessage = msg => { return 0; };
GeneralViewModel viewModel = new GeneralViewModel(
new Mock<ISettingsUtils>().Object,
SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
"GeneralSettings_RunningAsAdminText",
"GeneralSettings_RunningAsUserText",
@@ -106,7 +104,6 @@ namespace ViewModelTests
// Arrange
GeneralViewModel viewModel = new GeneralViewModel(
new Mock<ISettingsUtils>().Object,
SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
"GeneralSettings_RunningAsAdminText",
"GeneralSettings_RunningAsUserText",
@@ -140,7 +137,6 @@ namespace ViewModelTests
Func<string, int> SendRestartAdminIPCMessage = msg => { return 0; };
Func<string, int> SendCheckForUpdatesIPCMessage = msg => { return 0; };
viewModel = new GeneralViewModel(
new Mock<ISettingsUtils>().Object,
SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
"GeneralSettings_RunningAsAdminText",
"GeneralSettings_RunningAsUserText",
@@ -172,7 +168,6 @@ namespace ViewModelTests
Func<string, int> SendRestartAdminIPCMessage = msg => { return 0; };
Func<string, int> SendCheckForUpdatesIPCMessage = msg => { return 0; };
GeneralViewModel viewModel = new GeneralViewModel(
new Mock<ISettingsUtils>().Object,
SettingsRepository<GeneralSettings>.GetInstance(mockGeneralSettingsUtils.Object),
"GeneralSettings_RunningAsAdminText",
"GeneralSettings_RunningAsUserText",

View File

@@ -18,8 +18,7 @@ namespace ViewModelTests
[TestClass]
public class ImageResizer
{
// To have a consistent name.
public const string Module = ImageResizerSettings.ModuleName;
public const string Module = "ImageResizer";
private Mock<ISettingsUtils> mockGeneralSettingsUtils;

View File

@@ -36,7 +36,6 @@ namespace Microsoft.PowerToys.Settings.UI.Views
var settingsUtils = new SettingsUtils(new SystemIOProvider());
ViewModel = new GeneralViewModel(
settingsUtils,
SettingsRepository<GeneralSettings>.GetInstance(settingsUtils),
loader.GetString("GeneralSettings_RunningAsAdminText"),
loader.GetString("GeneralSettings_RunningAsUserText"),