Skip to content

Commit

Permalink
Don't update view if settings were not changed (#10407)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykhailopylyp committed Mar 24, 2021
1 parent 3601492 commit aba97a4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,16 @@ public virtual string ToJsonString()
// 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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -453,5 +453,10 @@ public bool ShowPluginsLoadingMessage
{
get => EnablePowerLauncher && !Plugins.Any();
}

public bool IsUpToDate(PowerLauncherSettings settings)
{
return this.settings.Equals(settings);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@ public PowerLauncherPage()
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();
Expand Down

0 comments on commit aba97a4

Please sign in to comment.