mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 11:17:53 +01:00
* 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:
@@ -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());
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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"),
|
||||
|
||||
Reference in New Issue
Block a user