Skip to content

Commit 1af9d06

Browse files
committed
Use api functions in other places
1 parent 24d43ed commit 1af9d06

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

Flow.Launcher.Core/Plugin/PluginManager.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ namespace Flow.Launcher.Core.Plugin
2323
/// </summary>
2424
public static class PluginManager
2525
{
26+
private static readonly string ClassName = nameof(PluginManager);
27+
2628
private static IEnumerable<PluginPair> _contextMenuPlugins;
2729

2830
public static List<PluginPair> AllPlugins { get; private set; }
@@ -194,7 +196,7 @@ public static async Task InitializePluginsAsync()
194196
{
195197
try
196198
{
197-
var milliseconds = await Stopwatch.DebugAsync($"|PluginManager.InitializePlugins|Init method time cost for <{pair.Metadata.Name}>",
199+
var milliseconds = await API.StopwatchLogDebugAsync(ClassName, $"Init method time cost for <{pair.Metadata.Name}>",
198200
() => pair.Plugin.InitAsync(new PluginInitContext(pair.Metadata, API)));
199201

200202
pair.Metadata.InitTime += milliseconds;
@@ -266,7 +268,7 @@ public static async Task<List<Result>> QueryForPluginAsync(PluginPair pair, Quer
266268

267269
try
268270
{
269-
var milliseconds = await Stopwatch.DebugAsync($"|PluginManager.QueryForPlugin|Cost for {metadata.Name}",
271+
var milliseconds = await API.StopwatchLogDebugAsync(ClassName, $"Cost for {metadata.Name}",
270272
async () => results = await pair.Plugin.QueryAsync(query, token).ConfigureAwait(false));
271273

272274
token.ThrowIfCancellationRequested();

Flow.Launcher.Core/Plugin/PluginsLoader.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@
1111
#pragma warning restore IDE0005
1212
using Flow.Launcher.Infrastructure.UserSettings;
1313
using Flow.Launcher.Plugin;
14-
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
1514

1615
namespace Flow.Launcher.Core.Plugin
1716
{
1817
public static class PluginsLoader
1918
{
19+
private static readonly string ClassName = nameof(PluginsLoader);
20+
21+
// We should not initialize API in static constructor because it will create another API instance
22+
private static IPublicAPI api = null;
23+
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
24+
2025
public static List<PluginPair> Plugins(List<PluginMetadata> metadatas, PluginsSettings settings)
2126
{
2227
var dotnetPlugins = DotNetPlugins(metadatas);
@@ -59,8 +64,7 @@ private static IEnumerable<PluginPair> DotNetPlugins(List<PluginMetadata> source
5964

6065
foreach (var metadata in metadatas)
6166
{
62-
var milliseconds = Stopwatch.Debug(
63-
$"|PluginsLoader.DotNetPlugins|Constructor init cost for {metadata.Name}", () =>
67+
var milliseconds = API.StopwatchLogDebug(ClassName, $"Constructor init cost for {metadata.Name}", () =>
6468
{
6569
Assembly assembly = null;
6670
IAsyncPlugin plugin = null;

Flow.Launcher/App.xaml.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
using Flow.Launcher.ViewModel;
2222
using Microsoft.Extensions.DependencyInjection;
2323
using Microsoft.Extensions.Hosting;
24-
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
2524

2625
namespace Flow.Launcher
2726
{
@@ -35,6 +34,8 @@ public partial class App : IDisposable, ISingleInstanceApp
3534

3635
#region Private Fields
3736

37+
private static readonly string ClassName = nameof(App);
38+
3839
private static bool _disposed;
3940
private MainWindow _mainWindow;
4041
private readonly MainViewModel _mainVM;
@@ -136,7 +137,7 @@ public static void Main()
136137

137138
private async void OnStartup(object sender, StartupEventArgs e)
138139
{
139-
await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
140+
await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
140141
{
141142
// Because new message box api uses MessageBoxEx window,
142143
// if it is created and closed before main window is created, it will cause the application to exit.
@@ -313,7 +314,7 @@ protected virtual void Dispose(bool disposing)
313314
_disposed = true;
314315
}
315316

316-
Stopwatch.Normal("|App.Dispose|Dispose cost", () =>
317+
API.StopwatchLogInfo(ClassName, "Dispose cost", () =>
317318
{
318319
Log.Info("|App.Dispose|Begin Flow Launcher dispose ----------------------------------------------------");
319320

0 commit comments

Comments
 (0)