mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-04 18:26:39 +02: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:
@@ -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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user