Skip to content

Commit 24d43ed

Browse files
committed
Use api functions in Program plugin
1 parent 19aa423 commit 24d43ed

File tree

1 file changed

+10
-10
lines changed
  • Plugins/Flow.Launcher.Plugin.Program

1 file changed

+10
-10
lines changed

Plugins/Flow.Launcher.Plugin.Program/Main.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
using System.Threading;
77
using System.Threading.Tasks;
88
using System.Windows.Controls;
9-
using Flow.Launcher.Infrastructure.Logger;
109
using Flow.Launcher.Infrastructure.UserSettings;
1110
using Flow.Launcher.Plugin.Program.Programs;
1211
using Flow.Launcher.Plugin.Program.Views;
1312
using Flow.Launcher.Plugin.Program.Views.Models;
1413
using Flow.Launcher.Plugin.SharedCommands;
1514
using Microsoft.Extensions.Caching.Memory;
1615
using Path = System.IO.Path;
17-
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
1816

1917
namespace Flow.Launcher.Plugin.Program
2018
{
@@ -32,6 +30,8 @@ public class Main : ISettingProvider, IAsyncPlugin, IPluginI18n, IContextMenu, I
3230

3331
internal static PluginInitContext Context { get; private set; }
3432

33+
private static readonly string ClassName = nameof(Main);
34+
3535
private static readonly List<Result> emptyResults = new();
3636

3737
private static readonly MemoryCacheOptions cacheOptions = new() { SizeLimit = 1560 };
@@ -109,7 +109,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
109109
}
110110
catch (OperationCanceledException)
111111
{
112-
Log.Debug("|Flow.Launcher.Plugin.Program.Main|Query operation cancelled");
112+
Context.API.LogDebug(ClassName, "Query operation cancelled");
113113
return emptyResults;
114114
}
115115
finally
@@ -188,7 +188,7 @@ public async Task InitAsync(PluginInitContext context)
188188

189189
var _win32sCount = 0;
190190
var _uwpsCount = 0;
191-
await Stopwatch.NormalAsync("|Flow.Launcher.Plugin.Program.Main|Preload programs cost", async () =>
191+
await Context.API.StopwatchLogInfoAsync(ClassName, "Preload programs cost", async () =>
192192
{
193193
var pluginCacheDirectory = Context.CurrentPluginMetadata.PluginCacheDirectoryPath;
194194
FilesFolders.ValidateDirectory(pluginCacheDirectory);
@@ -253,8 +253,8 @@ static void MoveFile(string sourcePath, string destinationPath)
253253
_uwpsCount = _uwps.Count;
254254
_uwpsLock.Release();
255255
});
256-
Log.Info($"|Flow.Launcher.Plugin.Program.Main|Number of preload win32 programs <{_win32sCount}>");
257-
Log.Info($"|Flow.Launcher.Plugin.Program.Main|Number of preload uwps <{_uwpsCount}>");
256+
Context.API.LogInfo(ClassName, $"Number of preload win32 programs <{_win32sCount}>");
257+
Context.API.LogInfo(ClassName, $"Number of preload uwps <{_uwpsCount}>");
258258

259259
var cacheEmpty = _win32sCount == 0 || _uwpsCount == 0;
260260

@@ -295,7 +295,7 @@ public static async Task IndexWin32ProgramsAsync()
295295
}
296296
catch (Exception e)
297297
{
298-
Log.Exception("|Flow.Launcher.Plugin.Program.Main|Failed to index Win32 programs", e);
298+
Context.API.LogException(ClassName, "Failed to index Win32 programs", e);
299299
}
300300
finally
301301
{
@@ -320,7 +320,7 @@ public static async Task IndexUwpProgramsAsync()
320320
}
321321
catch (Exception e)
322322
{
323-
Log.Exception("|Flow.Launcher.Plugin.Program.Main|Failed to index Uwp programs", e);
323+
Context.API.LogException(ClassName, "Failed to index Uwp programs", e);
324324
}
325325
finally
326326
{
@@ -332,12 +332,12 @@ public static async Task IndexProgramsAsync()
332332
{
333333
var win32Task = Task.Run(async () =>
334334
{
335-
await Stopwatch.NormalAsync("|Flow.Launcher.Plugin.Program.Main|Win32Program index cost", IndexWin32ProgramsAsync);
335+
await Context.API.StopwatchLogInfoAsync(ClassName, "Win32Program index cost", IndexWin32ProgramsAsync);
336336
});
337337

338338
var uwpTask = Task.Run(async () =>
339339
{
340-
await Stopwatch.NormalAsync("|Flow.Launcher.Plugin.Program.Main|UWPProgram index cost", IndexUwpProgramsAsync);
340+
await Context.API.StopwatchLogInfoAsync(ClassName, "UWPProgram index cost", IndexUwpProgramsAsync);
341341
});
342342

343343
await Task.WhenAll(win32Task, uwpTask).ConfigureAwait(false);

0 commit comments

Comments
 (0)