mirror of
https://github.com/microsoft/PowerToys
synced 2024-11-21 15:53:19 +00:00
[OOBE]Fix not shortcut not updating (#21175)
* [OOBE]Fix not shortcut not updating Fix for issue #20953. Activation key update in the OOBE window when the user changes it in the settings window. Add settings repository reference to the ViewModel constructor to use the repository settings object (and not create a second instance of it). * Fix for issue #20953. Unit test fixed.
This commit is contained in:
parent
ee904ae1b1
commit
ab41b61e84
@ -34,7 +34,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
public ColorPickerViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc)
|
||||
public ColorPickerViewModel(
|
||||
ISettingsUtils settingsUtils,
|
||||
ISettingsRepository<GeneralSettings> settingsRepository,
|
||||
ISettingsRepository<ColorPickerSettings> colorPickerSettingsRepository,
|
||||
Func<string, int> ipcMSGCallBackFunc)
|
||||
{
|
||||
// Obtain the general PowerToy settings configurations
|
||||
if (settingsRepository == null)
|
||||
@ -62,15 +66,14 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
GeneralSettingsConfig = settingsRepository.SettingsConfig;
|
||||
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
if (_settingsUtils.SettingsExists(ColorPickerSettings.ModuleName))
|
||||
|
||||
if (colorPickerSettingsRepository == null)
|
||||
{
|
||||
_colorPickerSettings = _settingsUtils.GetSettingsOrDefault<ColorPickerSettings>(ColorPickerSettings.ModuleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_colorPickerSettings = new ColorPickerSettings();
|
||||
throw new ArgumentNullException(nameof(colorPickerSettingsRepository));
|
||||
}
|
||||
|
||||
_colorPickerSettings = colorPickerSettingsRepository.SettingsConfig;
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.ColorPicker;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
|
@ -175,13 +175,15 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
if (Settings.Properties.ActivationShortcut != value)
|
||||
{
|
||||
Settings.Properties.ActivationShortcut = value;
|
||||
|
||||
NotifyPropertyChanged();
|
||||
|
||||
SendConfigMSG(
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
|
||||
MeasureToolSettings.ModuleName,
|
||||
JsonSerializer.Serialize(Settings)));
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
|
||||
MeasureToolSettings.ModuleName,
|
||||
JsonSerializer.Serialize(Settings)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -189,7 +191,6 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
public void NotifyPropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
if (propertyName == nameof(ShowContinuousCaptureWarning))
|
||||
{
|
||||
// Don't trigger a settings update if the changed property is for visual notification.
|
||||
|
@ -36,7 +36,11 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
|
||||
private Func<string, int> SendConfigMSG { get; }
|
||||
|
||||
public PowerLauncherViewModel(PowerLauncherSettings settings, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, Func<bool> isDark)
|
||||
public PowerLauncherViewModel(
|
||||
PowerLauncherSettings settings,
|
||||
ISettingsRepository<GeneralSettings> settingsRepository,
|
||||
Func<string, int> ipcMSGCallBackFunc,
|
||||
Func<bool> isDark)
|
||||
{
|
||||
if (settings == null)
|
||||
{
|
||||
|
@ -33,6 +33,7 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
public PowerOcrViewModel(
|
||||
ISettingsUtils settingsUtils,
|
||||
ISettingsRepository<GeneralSettings> settingsRepository,
|
||||
ISettingsRepository<PowerOcrSettings> powerOcrsettingsRepository,
|
||||
Func<string, int> ipcMSGCallBackFunc)
|
||||
{
|
||||
// To obtain the general settings configurations of PowerToys Settings.
|
||||
@ -50,15 +51,14 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
}
|
||||
|
||||
_settingsUtils = settingsUtils ?? throw new ArgumentNullException(nameof(settingsUtils));
|
||||
if (_settingsUtils.SettingsExists(PowerOcrSettings.ModuleName))
|
||||
|
||||
if (powerOcrsettingsRepository == null)
|
||||
{
|
||||
_powerOcrSettings = _settingsUtils.GetSettingsOrDefault<PowerOcrSettings>(PowerOcrSettings.ModuleName);
|
||||
}
|
||||
else
|
||||
{
|
||||
_powerOcrSettings = new PowerOcrSettings();
|
||||
throw new ArgumentNullException(nameof(powerOcrsettingsRepository));
|
||||
}
|
||||
|
||||
_powerOcrSettings = powerOcrsettingsRepository.SettingsConfig;
|
||||
|
||||
_isEnabled = GeneralSettingsConfig.Enabled.PowerOCR;
|
||||
|
||||
// set the callback functions value to hangle outgoing IPC message.
|
||||
@ -98,6 +98,8 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
|
||||
{
|
||||
_powerOcrSettings.Properties.ActivationShortcut = value;
|
||||
OnPropertyChanged(nameof(ActivationShortcut));
|
||||
|
||||
_settingsUtils.SaveSettings(_powerOcrSettings.ToJsonString(), PowerOcrSettings.ModuleName);
|
||||
NotifySettingsChanged();
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,10 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Globalization;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
@ -31,7 +32,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
|
||||
private string _settingsConfigFileFolder = string.Empty;
|
||||
|
||||
public VideoConferenceViewModel(ISettingsUtils settingsUtils, ISettingsRepository<GeneralSettings> settingsRepository, Func<string, int> ipcMSGCallBackFunc, Func<Task<string>> pickFileDialog, string configFileSubfolder = "")
|
||||
public VideoConferenceViewModel(
|
||||
ISettingsUtils settingsUtils,
|
||||
ISettingsRepository<GeneralSettings> settingsRepository,
|
||||
ISettingsRepository<VideoConferenceSettings> videoConferenceSettingsRepository,
|
||||
Func<string, int> ipcMSGCallBackFunc,
|
||||
Func<Task<string>> pickFileDialog,
|
||||
string configFileSubfolder = "")
|
||||
{
|
||||
PickFileDialog = pickFileDialog;
|
||||
|
||||
@ -48,16 +55,13 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
|
||||
_settingsConfigFileFolder = configFileSubfolder;
|
||||
|
||||
try
|
||||
if (videoConferenceSettingsRepository == null)
|
||||
{
|
||||
Settings = _settingsUtils.GetSettings<VideoConferenceSettings>(GetSettingsSubPath());
|
||||
}
|
||||
catch
|
||||
{
|
||||
Settings = new VideoConferenceSettings();
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), GetSettingsSubPath());
|
||||
throw new ArgumentNullException(nameof(videoConferenceSettingsRepository));
|
||||
}
|
||||
|
||||
Settings = videoConferenceSettingsRepository.SettingsConfig;
|
||||
|
||||
CameraNames = interop.CommonManaged.GetAllVideoCaptureDeviceNames();
|
||||
MicrophoneNames = interop.CommonManaged.GetAllActiveMicrophoneDeviceNames();
|
||||
MicrophoneNames.Insert(0, "[All]");
|
||||
@ -396,16 +400,21 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
|
||||
public string GetSettingsSubPath()
|
||||
{
|
||||
return _settingsConfigFileFolder + "\\" + ModuleName;
|
||||
return _settingsConfigFileFolder + (string.IsNullOrEmpty(_settingsConfigFileFolder) ? string.Empty : "\\") + ModuleName;
|
||||
}
|
||||
|
||||
public void RaisePropertyChanged([CallerMemberName] string propertyName = null)
|
||||
{
|
||||
OnPropertyChanged(propertyName);
|
||||
SndVideoConferenceSettings outsettings = new SndVideoConferenceSettings(Settings);
|
||||
SndModuleSettings<SndVideoConferenceSettings> ipcMessage = new SndModuleSettings<SndVideoConferenceSettings>(outsettings);
|
||||
SendConfigMSG(ipcMessage.ToJsonString());
|
||||
|
||||
_settingsUtils.SaveSettings(Settings.ToJsonString(), GetSettingsSubPath());
|
||||
|
||||
SendConfigMSG(
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
"{{ \"powertoys\": {{ \"{0}\": {1} }} }}",
|
||||
ModuleName,
|
||||
JsonSerializer.Serialize(Settings)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,10 +36,15 @@ namespace ViewModelTests
|
||||
var mockGeneralSettingsUtils = new SettingsUtils(mockGeneralIOProvider.Object, settingPathMock.Object);
|
||||
GeneralSettings originalGeneralSettings = mockGeneralSettingsUtils.GetSettingsOrDefault<GeneralSettings>();
|
||||
var generalSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<GeneralSettings>(mockGeneralSettingsUtils);
|
||||
var colorPickerSettingsRepository = new BackCompatTestProperties.MockSettingsRepository<ColorPickerSettings>(mockSettingsUtils);
|
||||
|
||||
// Act
|
||||
// Initialise View Model with test Config files
|
||||
using (var viewModel = new ColorPickerViewModel(mockSettingsUtils, generalSettingsRepository, ColorPickerIsEnabledByDefaultIPC))
|
||||
using (var viewModel = new ColorPickerViewModel(
|
||||
mockSettingsUtils,
|
||||
generalSettingsRepository,
|
||||
colorPickerSettingsRepository,
|
||||
ColorPickerIsEnabledByDefaultIPC))
|
||||
{
|
||||
// Assert
|
||||
// Verify that the old settings persisted
|
||||
@ -58,7 +63,11 @@ namespace ViewModelTests
|
||||
public void ColorPickerIsEnabledByDefault()
|
||||
{
|
||||
var mockSettingsUtils = ISettingsUtilsMocks.GetStubSettingsUtils<ColorPickerSettings>();
|
||||
using (var viewModel = new ColorPickerViewModel(ISettingsUtilsMocks.GetStubSettingsUtils<ColorPickerSettings>().Object, SettingsRepository<GeneralSettings>.GetInstance(ISettingsUtilsMocks.GetStubSettingsUtils<GeneralSettings>().Object), ColorPickerIsEnabledByDefaultIPC))
|
||||
using (var viewModel = new ColorPickerViewModel(
|
||||
ISettingsUtilsMocks.GetStubSettingsUtils<ColorPickerSettings>().Object,
|
||||
SettingsRepository<GeneralSettings>.GetInstance(ISettingsUtilsMocks.GetStubSettingsUtils<GeneralSettings>().Object),
|
||||
SettingsRepository<ColorPickerSettings>.GetInstance(new SettingsUtils()),
|
||||
ColorPickerIsEnabledByDefaultIPC))
|
||||
{
|
||||
Assert.IsTrue(viewModel.IsEnabled);
|
||||
}
|
||||
|
@ -15,7 +15,11 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
public ColorPickerPage()
|
||||
{
|
||||
var settingsUtils = new SettingsUtils();
|
||||
ViewModel = new ColorPickerViewModel(settingsUtils, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage);
|
||||
ViewModel = new ColorPickerViewModel(
|
||||
settingsUtils,
|
||||
SettingsRepository<GeneralSettings>.GetInstance(settingsUtils),
|
||||
SettingsRepository<ColorPickerSettings>.GetInstance(settingsUtils),
|
||||
ShellPage.SendDefaultIPCMessage);
|
||||
DataContext = ViewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Interfaces;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Utilities;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.ViewModels;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
@ -34,7 +35,8 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
InitializeComponent();
|
||||
var settingsUtils = new SettingsUtils();
|
||||
_lastIPCMessageSentTick = Environment.TickCount;
|
||||
PowerLauncherSettings settings = settingsUtils.GetSettingsOrDefault<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
|
||||
|
||||
PowerLauncherSettings settings = SettingsRepository<PowerLauncherSettings>.GetInstance(settingsUtils)?.SettingsConfig;
|
||||
ViewModel = new PowerLauncherViewModel(settings, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), SendDefaultIPCMessageTimed, App.IsDarkTheme);
|
||||
DataContext = ViewModel;
|
||||
_ = Helper.GetFileWatcher(PowerLauncherSettings.ModuleName, "settings.json", () =>
|
||||
@ -48,7 +50,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
PowerLauncherSettings powerLauncherSettings = null;
|
||||
try
|
||||
{
|
||||
powerLauncherSettings = settingsUtils.GetSettingsOrDefault<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
|
||||
powerLauncherSettings = SettingsRepository<PowerLauncherSettings>.GetInstance(settingsUtils)?.SettingsConfig;
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
|
@ -18,6 +18,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
ViewModel = new PowerOcrViewModel(
|
||||
settingsUtils,
|
||||
SettingsRepository<GeneralSettings>.GetInstance(settingsUtils),
|
||||
SettingsRepository<PowerOcrSettings>.GetInstance(settingsUtils),
|
||||
ShellPage.SendDefaultIPCMessage);
|
||||
DataContext = ViewModel;
|
||||
InitializeComponent();
|
||||
|
@ -34,7 +34,12 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
public VideoConferencePage()
|
||||
{
|
||||
var settingsUtils = new SettingsUtils();
|
||||
ViewModel = new VideoConferenceViewModel(settingsUtils, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage, PickFileDialog);
|
||||
ViewModel = new VideoConferenceViewModel(
|
||||
settingsUtils,
|
||||
SettingsRepository<GeneralSettings>.GetInstance(settingsUtils),
|
||||
SettingsRepository<VideoConferenceSettings>.GetInstance(settingsUtils),
|
||||
ShellPage.SendDefaultIPCMessage,
|
||||
PickFileDialog);
|
||||
DataContext = ViewModel;
|
||||
InitializeComponent();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user