mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
PowerLauncherSettings unit tests (#2276)
This commit is contained in:
committed by
GitHub
parent
ca7b6f139f
commit
7ec8d02c1f
@@ -12,19 +12,36 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
public class PowerLauncherViewModel : Observable
|
||||
{
|
||||
private const string POWERTOYNAME = "PowerLauncher";
|
||||
private PowerLauncherSettings settings;
|
||||
|
||||
public delegate void SendCallback(PowerLauncherSettings settings);
|
||||
|
||||
private readonly SendCallback callback;
|
||||
|
||||
public PowerLauncherViewModel()
|
||||
{
|
||||
if (SettingsUtils.SettingsExists(POWERTOYNAME))
|
||||
if (SettingsUtils.SettingsExists(PowerLauncherSettings.POWERTOYNAME))
|
||||
{
|
||||
settings = SettingsUtils.GetSettings<PowerLauncherSettings>(POWERTOYNAME);
|
||||
settings = SettingsUtils.GetSettings<PowerLauncherSettings>(PowerLauncherSettings.POWERTOYNAME);
|
||||
}
|
||||
else
|
||||
{
|
||||
settings = new PowerLauncherSettings();
|
||||
}
|
||||
|
||||
callback = (PowerLauncherSettings settings) =>
|
||||
{
|
||||
// Propagate changes to Power Launcher through IPC
|
||||
var propertiesJson = JsonSerializer.Serialize(settings.properties);
|
||||
ShellPage.DefaultSndMSGCallback(
|
||||
string.Format("{{ \"{0}\": {1} }}", PowerLauncherSettings.POWERTOYNAME, JsonSerializer.Serialize(settings.properties)));
|
||||
};
|
||||
}
|
||||
|
||||
public PowerLauncherViewModel(PowerLauncherSettings settings, SendCallback callback)
|
||||
{
|
||||
this.settings = settings;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
private void UpdateSettings([CallerMemberName] string propertyName = null)
|
||||
@@ -32,17 +49,8 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
// Notify UI of property change
|
||||
OnPropertyChanged(propertyName);
|
||||
|
||||
// Save settings to file
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true,
|
||||
};
|
||||
SettingsUtils.SaveSettings(JsonSerializer.Serialize(settings, options), POWERTOYNAME);
|
||||
|
||||
// Propagate changes to Power Launcher through IPC
|
||||
var propertiesJson = JsonSerializer.Serialize(settings.properties);
|
||||
ShellPage.DefaultSndMSGCallback(
|
||||
string.Format("{{ \"{0}\": {1} }}", POWERTOYNAME, JsonSerializer.Serialize(settings.properties)));
|
||||
settings.Save();
|
||||
callback(settings);
|
||||
}
|
||||
|
||||
public bool EnablePowerLauncher
|
||||
|
||||
Reference in New Issue
Block a user