mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-08 12:18:50 +02:00
Don't sort plugins every time, sort it when set it
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -25,8 +24,7 @@ namespace Wox.Core.Plugin
|
|||||||
private static List<KeyValuePair<PluginPair, IInstantQuery>> instantSearches;
|
private static List<KeyValuePair<PluginPair, IInstantQuery>> instantSearches;
|
||||||
private static IEnumerable<PluginPair> exclusiveSearchPlugins;
|
private static IEnumerable<PluginPair> exclusiveSearchPlugins;
|
||||||
private static List<KeyValuePair<PluginPair, IContextMenu>> contextMenuPlugins;
|
private static List<KeyValuePair<PluginPair, IContextMenu>> contextMenuPlugins;
|
||||||
|
private static List<PluginPair> plugins;
|
||||||
private static List<PluginPair> plugins = new List<PluginPair>();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Directories that will hold Wox plugin directory
|
/// Directories that will hold Wox plugin directory
|
||||||
@@ -35,10 +33,8 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
public static List<PluginPair> AllPlugins
|
public static List<PluginPair> AllPlugins
|
||||||
{
|
{
|
||||||
get
|
get { return plugins; }
|
||||||
{
|
private set { plugins = value.OrderBy(o => o.Metadata.Name).ToList(); }
|
||||||
return plugins.OrderBy(o => o.Metadata.Name).ToList();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IPublicAPI API { private set; get; }
|
public static IPublicAPI API { private set; get; }
|
||||||
@@ -81,16 +77,17 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
SetupPluginDirectories();
|
SetupPluginDirectories();
|
||||||
API = api;
|
API = api;
|
||||||
plugins.Clear();
|
AllPlugins?.Clear();
|
||||||
|
|
||||||
pluginMetadatas = PluginConfig.Parse(pluginDirectories);
|
pluginMetadatas = PluginConfig.Parse(pluginDirectories);
|
||||||
plugins.AddRange(new CSharpPluginLoader().LoadPlugin(pluginMetadatas));
|
AllPlugins = (new CSharpPluginLoader().LoadPlugin(pluginMetadatas)).
|
||||||
plugins.AddRange(new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(pluginMetadatas));
|
Concat(new JsonRPCPluginLoader<PythonPlugin>().LoadPlugin(pluginMetadatas)).
|
||||||
|
ToList();
|
||||||
|
|
||||||
//load plugin i18n languages
|
//load plugin i18n languages
|
||||||
ResourceMerger.ApplyPluginLanguages();
|
ResourceMerger.ApplyPluginLanguages();
|
||||||
|
|
||||||
foreach (PluginPair pluginPair in plugins)
|
foreach (PluginPair pluginPair in AllPlugins)
|
||||||
{
|
{
|
||||||
PluginPair pair = pluginPair;
|
PluginPair pair = pluginPair;
|
||||||
ThreadPool.QueueUserWorkItem(o =>
|
ThreadPool.QueueUserWorkItem(o =>
|
||||||
@@ -205,7 +202,7 @@ namespace Wox.Core.Plugin
|
|||||||
private static bool IsVailldActionKeyword(string actionKeyword)
|
private static bool IsVailldActionKeyword(string actionKeyword)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(actionKeyword) || actionKeyword == Query.ActionKeywordWildcardSign) return false;
|
if (string.IsNullOrEmpty(actionKeyword) || actionKeyword == Query.ActionKeywordWildcardSign) return false;
|
||||||
PluginPair pair = plugins.FirstOrDefault(o => o.Metadata.ActionKeyword == actionKeyword);
|
PluginPair pair = AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == actionKeyword);
|
||||||
if (pair == null) return false;
|
if (pair == null) return false;
|
||||||
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pair.Metadata.ID);
|
var customizedPluginConfig = UserSettingStorage.Instance.CustomizedPluginConfigs.FirstOrDefault(o => o.ID == pair.Metadata.ID);
|
||||||
return customizedPluginConfig == null || !customizedPluginConfig.Disabled;
|
return customizedPluginConfig == null || !customizedPluginConfig.Disabled;
|
||||||
@@ -244,13 +241,13 @@ namespace Wox.Core.Plugin
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static PluginPair GetPlugin(string id)
|
public static PluginPair GetPlugin(string id)
|
||||||
{
|
{
|
||||||
return plugins.FirstOrDefault(o => o.Metadata.ID == id);
|
return AllPlugins.FirstOrDefault(o => o.Metadata.ID == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PluginPair GetExclusivePlugin(Query query)
|
private static PluginPair GetExclusivePlugin(Query query)
|
||||||
{
|
{
|
||||||
exclusiveSearchPlugins = exclusiveSearchPlugins ??
|
exclusiveSearchPlugins = exclusiveSearchPlugins ??
|
||||||
plugins.Where(p => p.Plugin.GetType().GetInterfaces().Contains(typeof(IExclusiveQuery)));
|
AllPlugins.Where(p => p.Plugin.GetType().GetInterfaces().Contains(typeof(IExclusiveQuery)));
|
||||||
var plugin = exclusiveSearchPlugins.FirstOrDefault(p => ((IExclusiveQuery)p.Plugin).IsExclusiveQuery(query));
|
var plugin = exclusiveSearchPlugins.FirstOrDefault(p => ((IExclusiveQuery)p.Plugin).IsExclusiveQuery(query));
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
@@ -259,7 +256,7 @@ namespace Wox.Core.Plugin
|
|||||||
{
|
{
|
||||||
//if a query doesn't contain a vaild action keyword, it should not be a action keword plugin query
|
//if a query doesn't contain a vaild action keyword, it should not be a action keword plugin query
|
||||||
if (string.IsNullOrEmpty(query.ActionKeyword)) return null;
|
if (string.IsNullOrEmpty(query.ActionKeyword)) return null;
|
||||||
return plugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.ActionKeyword);
|
return AllPlugins.FirstOrDefault(o => o.Metadata.ActionKeyword == query.ActionKeyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PluginPair GetNonSystemPlugin(Query query)
|
private static PluginPair GetNonSystemPlugin(Query query)
|
||||||
@@ -269,7 +266,7 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
private static List<PluginPair> GetSystemPlugins()
|
private static List<PluginPair> GetSystemPlugins()
|
||||||
{
|
{
|
||||||
return plugins.Where(o => IsSystemPlugin(o.Metadata)).ToList();
|
return AllPlugins.Where(o => IsSystemPlugin(o.Metadata)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Result> GetPluginContextMenus(Result result)
|
public static List<Result> GetPluginContextMenus(Result result)
|
||||||
|
|||||||
Reference in New Issue
Block a user