mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
Do not load plugin when it is disabled (#10515)
This commit is contained in:
@@ -10,6 +10,7 @@ using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using PowerLauncher.Properties;
|
||||
using Wox.Infrastructure;
|
||||
using Wox.Infrastructure.Storage;
|
||||
using Wox.Plugin;
|
||||
@@ -49,7 +50,10 @@ namespace PowerLauncher.Plugin
|
||||
{
|
||||
if (_allPlugins == null)
|
||||
{
|
||||
_allPlugins = PluginsLoader.Plugins(PluginConfig.Parse(Directories));
|
||||
_allPlugins = PluginConfig.Parse(Directories)
|
||||
.Where(x => x.Language.ToUpperInvariant() == AllowedLanguage.CSharp)
|
||||
.Select(x => new PluginPair(x))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,23 +123,15 @@ namespace PowerLauncher.Plugin
|
||||
var failedPlugins = new ConcurrentQueue<PluginPair>();
|
||||
Parallel.ForEach(AllPlugins, pair =>
|
||||
{
|
||||
try
|
||||
if (pair.Metadata.Disabled)
|
||||
{
|
||||
var milliseconds = Stopwatch.Debug($"PluginManager.InitializePlugins - Init method time cost for <{pair.Metadata.Name}>", () =>
|
||||
{
|
||||
pair.Plugin.Init(new PluginInitContext
|
||||
{
|
||||
CurrentPluginMetadata = pair.Metadata,
|
||||
API = API,
|
||||
});
|
||||
});
|
||||
pair.Metadata.InitTime += milliseconds;
|
||||
Log.Info($"Total init cost for <{pair.Metadata.Name}> is <{pair.Metadata.InitTime}ms>", MethodBase.GetCurrentMethod().DeclaringType);
|
||||
return;
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
pair.LoadPlugin(API);
|
||||
|
||||
if (!pair.IsPluginLoaded)
|
||||
{
|
||||
Log.Exception($"Fail to Init plugin: {pair.Metadata.Name}", e, MethodBase.GetCurrentMethod().DeclaringType);
|
||||
pair.Metadata.Disabled = true;
|
||||
failedPlugins.Enqueue(pair);
|
||||
}
|
||||
});
|
||||
@@ -145,7 +141,8 @@ namespace PowerLauncher.Plugin
|
||||
if (failedPlugins.Any())
|
||||
{
|
||||
var failed = string.Join(",", failedPlugins.Select(x => x.Metadata.Name));
|
||||
API.ShowMsg($"Fail to Init Plugins", $"Plugins: {failed} - fail to load and would be disabled, please contact plugin creator for help", string.Empty, false);
|
||||
var description = string.Format(CultureInfo.CurrentCulture, Resources.FailedToInitializePluginsDescription, failed);
|
||||
API.ShowMsg(Resources.FailedToInitializePluginsTitle, description, string.Empty, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,6 +159,11 @@ namespace PowerLauncher.Plugin
|
||||
throw new ArgumentNullException(nameof(pair));
|
||||
}
|
||||
|
||||
if (!pair.IsPluginLoaded)
|
||||
{
|
||||
return new List<Result>();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
List<Result> results = null;
|
||||
|
||||
Reference in New Issue
Block a user