update plugins settings with changes (#10064)

This commit is contained in:
Mykhailo Pylyp 2021-03-05 05:43:08 -08:00 committed by GitHub
parent e66db5cc10
commit 0c3f8af4d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -75,10 +75,10 @@ namespace PowerLauncher
var overloadSettings = _settingsUtils.GetSettingsOrDefault<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
if (overloadSettings.Plugins == null || !overloadSettings.Plugins.Any())
if (overloadSettings.Plugins == null || overloadSettings.Plugins.Count() != PluginManager.AllPlugins.Count)
{
// Needed to be consistent with old settings
overloadSettings.Plugins = GetDefaultPluginsSettings();
overloadSettings.Plugins = CombineWithDefaultSettings(overloadSettings.Plugins);
_settingsUtils.SaveSettings(overloadSettings.ToJsonString(), PowerLauncherSettings.ModuleName);
}
else
@ -173,6 +173,20 @@ namespace PowerLauncher
return model.ToString();
}
private static List<PowerLauncherPluginSettings> CombineWithDefaultSettings(IEnumerable<PowerLauncherPluginSettings> plugins)
{
var results = GetDefaultPluginsSettings().ToDictionary(x => x.Id);
foreach (var plugin in plugins)
{
if (results.ContainsKey(plugin.Id))
{
results[plugin.Id] = plugin;
}
}
return results.Values.ToList();
}
private static IEnumerable<PowerLauncherPluginSettings> GetDefaultPluginsSettings()
{
return PluginManager.AllPlugins.Select(x => new PowerLauncherPluginSettings()