Don't update view if settings were not changed (#10407)

This commit is contained in:
Mykhailo Pylyp
2021-03-24 16:13:33 +02:00
committed by GitHub
parent 3601492ce1
commit aba97a419c
3 changed files with 29 additions and 13 deletions

View File

@@ -23,5 +23,16 @@ namespace Microsoft.PowerToys.Settings.UI.Library
// By default JsonSerializer will only serialize the properties in the base class. This can be avoided by passing the object type (more details at https://stackoverflow.com/a/62498888)
return JsonSerializer.Serialize(this, GetType());
}
public override int GetHashCode()
{
return ToJsonString().GetHashCode();
}
public override bool Equals(object obj)
{
var settings = obj as BasePTModuleSettings;
return settings?.ToJsonString() == ToJsonString();
}
}
}

View File

@@ -453,5 +453,10 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
{
get => EnablePowerLauncher && !Plugins.Any();
}
public bool IsUpToDate(PowerLauncherSettings settings)
{
return this.settings.Equals(settings);
}
}
}

View File

@@ -28,24 +28,24 @@ namespace Microsoft.PowerToys.Settings.UI.Views
DataContext = ViewModel;
_ = Helper.GetFileWatcher(PowerLauncherSettings.ModuleName, "settings.json", () =>
{
_ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
PowerLauncherSettings powerLauncherSettings = null;
try
{
PowerLauncherSettings powerLauncherSettings = null;
try
{
powerLauncherSettings = settingsUtils.GetSettingsOrDefault<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
}
catch (IOException ex)
{
Logger.LogInfo(ex.Message);
}
powerLauncherSettings = settingsUtils.GetSettingsOrDefault<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
}
catch (IOException ex)
{
Logger.LogInfo(ex.Message);
}
if (powerLauncherSettings != null)
if (powerLauncherSettings != null && !ViewModel.IsUpToDate(powerLauncherSettings))
{
_ = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
DataContext = ViewModel = new PowerLauncherViewModel(powerLauncherSettings, SettingsRepository<GeneralSettings>.GetInstance(settingsUtils), ShellPage.SendDefaultIPCMessage, App.IsDarkTheme);
this.Bindings.Update();
}
});
});
}
});
var loader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();