[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:
Laszlo Nemeth
2022-10-13 09:46:30 +02:00
committed by GitHub
parent ee904ae1b1
commit ab41b61e84
10 changed files with 79 additions and 39 deletions

View File

@@ -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)));
}
}