mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
fix 0 init time record
This commit is contained in:
@@ -93,7 +93,7 @@ namespace Wox.Core.Plugin
|
|||||||
API = api;
|
API = api;
|
||||||
Parallel.ForEach(AllPlugins, pair =>
|
Parallel.ForEach(AllPlugins, pair =>
|
||||||
{
|
{
|
||||||
var milliseconds = Stopwatch.Normal($"Plugin init: {pair.Metadata.Name}", () =>
|
var milliseconds = Stopwatch.Debug($"Plugin init: {pair.Metadata.Name}", () =>
|
||||||
{
|
{
|
||||||
pair.Plugin.Init(new PluginInitContext
|
pair.Plugin.Init(new PluginInitContext
|
||||||
{
|
{
|
||||||
@@ -101,7 +101,8 @@ namespace Wox.Core.Plugin
|
|||||||
API = API
|
API = API
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
pair.Metadata.InitTime = milliseconds;
|
pair.Metadata.InitTime += milliseconds;
|
||||||
|
Log.Info($"Total init for {pair.Metadata.Name}: {pair.Metadata.InitTime}ms");
|
||||||
InternationalizationManager.Instance.UpdatePluginMetadataTranslations(pair);
|
InternationalizationManager.Instance.UpdatePluginMetadataTranslations(pair);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -33,50 +33,56 @@ namespace Wox.Core.Plugin
|
|||||||
|
|
||||||
foreach (var metadata in metadatas)
|
foreach (var metadata in metadatas)
|
||||||
{
|
{
|
||||||
|
var milliseconds = Stopwatch.Debug($"C# plugin constructor init: {metadata.Name}", () =>
|
||||||
|
{
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
var assembly = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
var assembly = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
||||||
var types = assembly.GetTypes();
|
var types = assembly.GetTypes();
|
||||||
var type = types.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IPlugin)));
|
var type = types.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IPlugin)));
|
||||||
var plugin = (IPlugin)Activator.CreateInstance(type);
|
var plugin = (IPlugin)Activator.CreateInstance(type);
|
||||||
#else
|
#else
|
||||||
Assembly assembly;
|
Assembly assembly;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
assembly = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
assembly = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception(new WoxPluginException(metadata.Name, "Couldn't load assembly", e));
|
Log.Exception(new WoxPluginException(metadata.Name, "Couldn't load assembly", e));
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
var types = assembly.GetTypes();
|
var types = assembly.GetTypes();
|
||||||
Type type;
|
Type type;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
type = types.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IPlugin)));
|
type = types.First(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IPlugin)));
|
||||||
}
|
}
|
||||||
catch (InvalidOperationException e)
|
catch (InvalidOperationException e)
|
||||||
{
|
{
|
||||||
Log.Exception(new WoxPluginException(metadata.Name, "Can't find class implement IPlugin", e));
|
Log.Exception(new WoxPluginException(metadata.Name, "Can't find class implement IPlugin", e));
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
IPlugin plugin;
|
IPlugin plugin;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plugin = (IPlugin)Activator.CreateInstance(type);
|
plugin = (IPlugin)Activator.CreateInstance(type);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Exception(new WoxPluginException(metadata.Name, "Can't create instance", e));
|
Log.Exception(new WoxPluginException(metadata.Name, "Can't create instance", e));
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
PluginPair pair = new PluginPair
|
PluginPair pair = new PluginPair
|
||||||
{
|
{
|
||||||
Plugin = plugin,
|
Plugin = plugin,
|
||||||
Metadata = metadata
|
Metadata = metadata
|
||||||
};
|
};
|
||||||
plugins.Add(pair);
|
plugins.Add(pair);
|
||||||
|
});
|
||||||
|
metadata.InitTime += milliseconds;
|
||||||
|
|
||||||
}
|
}
|
||||||
return plugins;
|
return plugins;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user