mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-06 11:16:51 +02:00
structure change
This commit is contained in:
@@ -30,25 +30,18 @@ namespace WinAlfred.PluginLoader
|
||||
|
||||
private static void ParseSystemPlugins()
|
||||
{
|
||||
try
|
||||
{
|
||||
Assembly asm = Assembly.GetAssembly(typeof (CMD));
|
||||
List<Type> types = asm.GetTypes().Where(o => o.GetInterfaces().Contains(typeof(ISystemPlugin))).ToList();
|
||||
foreach (Type type in types)
|
||||
{
|
||||
ISystemPlugin sysPlugin = Activator.CreateInstance(types[0]) as ISystemPlugin;
|
||||
PluginMetadata metadata = new PluginMetadata();
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.Error(string.Format("Cound't load system plugin: {0}", e.Message));
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
PluginMetadata metadata = new PluginMetadata();
|
||||
metadata.Name = "System Plugins";
|
||||
metadata.Author = "System";
|
||||
metadata.Description = "system plugins collection";
|
||||
metadata.Language = AllowedLanguage.CSharp;
|
||||
metadata.Version = "1.0";
|
||||
metadata.PluginType = PluginType.System;
|
||||
metadata.ActionKeyword = "*";
|
||||
metadata.ExecuteFileName = "WinAlfred.Plugin.System.dll";
|
||||
metadata.ExecuteFilePath = AppDomain.CurrentDomain.BaseDirectory + metadata.ExecuteFileName;
|
||||
metadata.PluginDirecotry = AppDomain.CurrentDomain.BaseDirectory;
|
||||
pluginMetadatas.Add(metadata);
|
||||
}
|
||||
|
||||
private static void ParseThirdPartyPlugins()
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Reflection;
|
||||
using System.Threading;
|
||||
using WinAlfred.Helper;
|
||||
using WinAlfred.Plugin;
|
||||
using WinAlfred.Plugin.System;
|
||||
|
||||
namespace WinAlfred.PluginLoader
|
||||
{
|
||||
@@ -20,28 +21,23 @@ namespace WinAlfred.PluginLoader
|
||||
try
|
||||
{
|
||||
Assembly asm = Assembly.LoadFile(metadata.ExecuteFilePath);
|
||||
List<Type> types = asm.GetTypes().Where(o => o.GetInterfaces().Contains(typeof (IPlugin))).ToList();
|
||||
List<Type> types = asm.GetTypes().Where(o => o.IsClass && o.GetInterfaces().Contains(typeof(IPlugin)) || o.GetInterfaces().Contains(typeof(ISystemPlugin))).ToList();
|
||||
if (types.Count == 0)
|
||||
{
|
||||
Log.Error(string.Format("Cound't load plugin {0}: didn't find the class who implement IPlugin",
|
||||
metadata.Name));
|
||||
continue;
|
||||
}
|
||||
if (types.Count > 1)
|
||||
{
|
||||
Log.Error(
|
||||
string.Format(
|
||||
"Cound't load plugin {0}: find more than one class who implement IPlugin, there should only one class implement IPlugin",
|
||||
metadata.Name));
|
||||
continue;
|
||||
}
|
||||
|
||||
PluginPair pair = new PluginPair()
|
||||
foreach (Type type in types)
|
||||
{
|
||||
Plugin = Activator.CreateInstance(types[0]) as IPlugin,
|
||||
Metadata = metadata
|
||||
};
|
||||
plugins.Add(pair);
|
||||
PluginPair pair = new PluginPair()
|
||||
{
|
||||
Plugin = Activator.CreateInstance(type) as IPlugin,
|
||||
Metadata = metadata
|
||||
};
|
||||
plugins.Add(pair);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -61,10 +57,7 @@ namespace WinAlfred.PluginLoader
|
||||
|
||||
private void InitPlugin(List<PluginPair> plugins)
|
||||
{
|
||||
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
|
||||
{
|
||||
new Thread(plugin.Init).Start();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using WinAlfred.Plugin;
|
||||
|
||||
namespace WinAlfred.PluginLoader
|
||||
@@ -10,11 +11,24 @@ namespace WinAlfred.PluginLoader
|
||||
{
|
||||
private static List<PluginPair> plugins = new List<PluginPair>();
|
||||
|
||||
public static void Init()
|
||||
public static void Init(MainWindow window)
|
||||
{
|
||||
plugins.Clear();
|
||||
plugins.AddRange(new PythonPluginLoader().LoadPlugin());
|
||||
plugins.AddRange(new CSharpPluginLoader().LoadPlugin());
|
||||
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
|
||||
{
|
||||
IPlugin plugin1 = plugin;
|
||||
ThreadPool.QueueUserWorkItem(o => plugin1.Init(new PluginInitContext()
|
||||
{
|
||||
Plugins = plugins,
|
||||
ChangeQuery = s =>
|
||||
{
|
||||
window.tbQuery.Text = s;
|
||||
window.ShowWinAlfred();
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public static List<PluginPair> AllPlugins
|
||||
|
||||
@@ -22,10 +22,6 @@ namespace WinAlfred.PluginLoader
|
||||
plugins.Add(pair);
|
||||
}
|
||||
|
||||
foreach (IPlugin plugin in plugins.Select(pluginPair => pluginPair.Plugin))
|
||||
{
|
||||
new Thread(plugin.Init).Start();
|
||||
}
|
||||
return plugins;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace WinAlfred.PluginLoader
|
||||
|
||||
}
|
||||
|
||||
public void Init()
|
||||
public void Init(PluginInitContext context)
|
||||
{
|
||||
InitPythonEnv();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user