tweak plugin settings (#9522)

This commit is contained in:
Mykhailo Pylyp
2021-02-10 15:12:42 +02:00
committed by GitHub
parent ec6b9acad9
commit d92ff6d45d
24 changed files with 240 additions and 398 deletions

View File

@@ -3,8 +3,10 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Threading;
using System.Windows.Input;
using Microsoft.PowerToys.Common.UI;
@@ -54,6 +56,7 @@ namespace PowerLauncher
Log.Info("PT Run settings.json was missing, creating a new one", GetType());
var defaultSettings = new PowerLauncherSettings();
defaultSettings.Plugins = GetPluginsSettings();
defaultSettings.Save(_settingsUtils);
}
}
@@ -72,6 +75,26 @@ namespace PowerLauncher
var overloadSettings = _settingsUtils.GetSettingsOrDefault<PowerLauncherSettings>(PowerLauncherSettings.ModuleName);
if (overloadSettings.Plugins == null || !overloadSettings.Plugins.Any())
{
// Needed to be consistent with old settings
overloadSettings.Plugins = GetPluginsSettings();
_settingsUtils.SaveSettings(overloadSettings.ToJsonString(), PowerLauncherSettings.ModuleName);
}
else
{
foreach (var setting in overloadSettings.Plugins)
{
var plugin = PluginManager.AllPlugins.FirstOrDefault(x => x.Metadata.ID == setting.Id);
if (plugin != null)
{
plugin.Metadata.Disabled = setting.Disabled;
plugin.Metadata.ActionKeyword = setting.ActionKeyword;
plugin.Metadata.IsGlobal = setting.IsGlobal;
}
}
}
var openPowerlauncher = ConvertHotkey(overloadSettings.Properties.OpenPowerLauncher);
if (_settings.Hotkey != openPowerlauncher)
{
@@ -160,5 +183,21 @@ namespace PowerLauncher
HotkeyModel model = new HotkeyModel(hotkey.Alt, hotkey.Shift, hotkey.Win, hotkey.Ctrl, key);
return model.ToString();
}
private static IEnumerable<PowerLauncherPluginSettings> GetPluginsSettings()
{
return PluginManager.AllPlugins.Select(x => x.Metadata).Select(x => new PowerLauncherPluginSettings
{
Id = x.ID,
Name = x.Name,
Description = x.Description,
Author = x.Author,
Disabled = x.Disabled,
IsGlobal = x.IsGlobal,
ActionKeyword = x.ActionKeyword,
IconPathDark = x.IcoPathDark,
IconPathLight = x.IcoPathLight,
});
}
}
}