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