mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 19:26:39 +02:00
Add IContextMenu interface & lazy load context menus
This commit is contained in:
@@ -12,37 +12,18 @@ namespace Wox.Core
|
||||
{
|
||||
public static List<KeyValuePair<PluginPair, T>> LoadPluginInterfaces<T>() where T : class
|
||||
{
|
||||
List<PluginMetadata> CSharpPluginMetadatas = PluginManager.AllPlugins.Select(o => o.Metadata).Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList();
|
||||
List<KeyValuePair<PluginPair, T>> plugins = new List<KeyValuePair<PluginPair, T>>();
|
||||
foreach (PluginMetadata metadata in CSharpPluginMetadatas)
|
||||
List<KeyValuePair<PluginPair, T>> results = new List<KeyValuePair<PluginPair, T>>();
|
||||
foreach (PluginPair pluginPair in PluginManager.AllPlugins)
|
||||
{
|
||||
try
|
||||
//need to load types from AllPlugins
|
||||
//PluginInitContext is only available in this instance
|
||||
T type = pluginPair.Plugin as T;
|
||||
if (type != null)
|
||||
{
|
||||
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
||||
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(T))).ToList();
|
||||
if (types.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (Type type in types)
|
||||
{
|
||||
plugins.Add(new KeyValuePair<PluginPair, T>(PluginManager.AllPlugins.First(o => o.Metadata.ID == metadata.ID),
|
||||
Activator.CreateInstance(type) as T));
|
||||
}
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message));
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
results.Add(new KeyValuePair<PluginPair, T>(pluginPair,type));
|
||||
}
|
||||
}
|
||||
|
||||
return plugins;
|
||||
return results;
|
||||
}
|
||||
|
||||
public static List<T> LoadInterfacesFromAppDomain<T>() where T : class
|
||||
|
||||
Reference in New Issue
Block a user