mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
[Settings] update additional options for launcher plugins (#12920)
This commit is contained in:
committed by
GitHub
parent
2fe6282157
commit
f00bf7cf19
@@ -2,7 +2,6 @@
|
|||||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
// See the LICENSE file in the project root for more information.
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Abstractions;
|
using System.IO.Abstractions;
|
||||||
@@ -39,6 +38,10 @@ namespace PowerLauncher
|
|||||||
_settings = settings;
|
_settings = settings;
|
||||||
_themeManager = themeManager;
|
_themeManager = themeManager;
|
||||||
|
|
||||||
|
var overloadSettings = _settingsUtils.GetSettingsOrDefault<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
|
||||||
|
UpdateSettings(overloadSettings);
|
||||||
|
_settingsUtils.SaveSettings(overloadSettings.ToJsonString(), PowerLauncherSettings.ModuleName);
|
||||||
|
|
||||||
// Apply theme at startup
|
// Apply theme at startup
|
||||||
_themeManager.ChangeTheme(_settings.Theme, true);
|
_themeManager.ChangeTheme(_settings.Theme, true);
|
||||||
}
|
}
|
||||||
@@ -85,19 +88,10 @@ namespace PowerLauncher
|
|||||||
Log.Info($"Successfully read new settings. retryCount={retryCount}", GetType());
|
Log.Info($"Successfully read new settings. retryCount={retryCount}", GetType());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (overloadSettings.Plugins == null || overloadSettings.Plugins.Count() != PluginManager.AllPlugins.Count)
|
foreach (var setting in overloadSettings.Plugins)
|
||||||
{
|
{
|
||||||
// Needed to be consistent with old settings
|
var plugin = PluginManager.AllPlugins.FirstOrDefault(x => x.Metadata.ID == setting.Id);
|
||||||
overloadSettings.Plugins = CombineWithDefaultSettings(overloadSettings.Plugins);
|
plugin?.Update(setting, App.API);
|
||||||
_settingsUtils.SaveSettings(overloadSettings.ToJsonString(), PowerLauncherSettings.ModuleName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
foreach (var setting in overloadSettings.Plugins)
|
|
||||||
{
|
|
||||||
var plugin = PluginManager.AllPlugins.FirstOrDefault(x => x.Metadata.ID == setting.Id);
|
|
||||||
plugin?.Update(setting, App.API);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var openPowerlauncher = ConvertHotkey(overloadSettings.Properties.OpenPowerLauncher);
|
var openPowerlauncher = ConvertHotkey(overloadSettings.Properties.OpenPowerLauncher);
|
||||||
@@ -179,20 +173,6 @@ namespace PowerLauncher
|
|||||||
return model.ToString();
|
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 string GetIcon(PluginMetadata metadata, string iconPath)
|
private static string GetIcon(PluginMetadata metadata, string iconPath)
|
||||||
{
|
{
|
||||||
var pluginDirectory = Path.GetFileName(metadata.PluginDirectory);
|
var pluginDirectory = Path.GetFileName(metadata.PluginDirectory);
|
||||||
@@ -215,5 +195,40 @@ namespace PowerLauncher
|
|||||||
AdditionalOptions = x.Plugin is ISettingProvider ? (x.Plugin as ISettingProvider).AdditionalOptions : new List<PluginAdditionalOption>(),
|
AdditionalOptions = x.Plugin is ISettingProvider ? (x.Plugin as ISettingProvider).AdditionalOptions : new List<PluginAdditionalOption>(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Add new plugins and updates additional options for existing ones
|
||||||
|
/// </summary>
|
||||||
|
private static void UpdateSettings(PowerLauncherSettings settings)
|
||||||
|
{
|
||||||
|
var defaultPlugins = GetDefaultPluginsSettings().ToDictionary(x => x.Id);
|
||||||
|
foreach (PowerLauncherPluginSettings plugin in settings.Plugins)
|
||||||
|
{
|
||||||
|
if (defaultPlugins.ContainsKey(plugin.Id))
|
||||||
|
{
|
||||||
|
var additionalOptions = CombineAdditionalOptions(defaultPlugins[plugin.Id].AdditionalOptions, plugin.AdditionalOptions);
|
||||||
|
plugin.Name = defaultPlugins[plugin.Id].Name;
|
||||||
|
plugin.Description = defaultPlugins[plugin.Id].Description;
|
||||||
|
defaultPlugins[plugin.Id] = plugin;
|
||||||
|
defaultPlugins[plugin.Id].AdditionalOptions = additionalOptions;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
settings.Plugins = defaultPlugins.Values.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IEnumerable<PluginAdditionalOption> CombineAdditionalOptions(IEnumerable<PluginAdditionalOption> defaultAdditionalOptions, IEnumerable<PluginAdditionalOption> additionalOptions)
|
||||||
|
{
|
||||||
|
var defaultOptions = defaultAdditionalOptions.ToDictionary(x => x.Key);
|
||||||
|
foreach (var option in additionalOptions)
|
||||||
|
{
|
||||||
|
if (defaultOptions.ContainsKey(option.Key))
|
||||||
|
{
|
||||||
|
defaultOptions[option.Key].Value = option.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultOptions.Values;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user