mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Merge branch 'dev' into 250320BookmarkFavicon
This commit is contained in:
commit
ab34e83c5e
9 changed files with 74 additions and 54 deletions
|
|
@ -23,6 +23,8 @@ namespace Flow.Launcher.Core.Plugin
|
|||
/// </summary>
|
||||
public static class PluginManager
|
||||
{
|
||||
private static readonly string ClassName = nameof(PluginManager);
|
||||
|
||||
private static IEnumerable<PluginPair> _contextMenuPlugins;
|
||||
|
||||
public static List<PluginPair> AllPlugins { get; private set; }
|
||||
|
|
@ -194,7 +196,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
{
|
||||
try
|
||||
{
|
||||
var milliseconds = await Stopwatch.DebugAsync($"|PluginManager.InitializePlugins|Init method time cost for <{pair.Metadata.Name}>",
|
||||
var milliseconds = await API.StopwatchLogDebugAsync(ClassName, $"Init method time cost for <{pair.Metadata.Name}>",
|
||||
() => pair.Plugin.InitAsync(new PluginInitContext(pair.Metadata, API)));
|
||||
|
||||
pair.Metadata.InitTime += milliseconds;
|
||||
|
|
@ -266,7 +268,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
|
||||
try
|
||||
{
|
||||
var milliseconds = await Stopwatch.DebugAsync($"|PluginManager.QueryForPlugin|Cost for {metadata.Name}",
|
||||
var milliseconds = await API.StopwatchLogDebugAsync(ClassName, $"Cost for {metadata.Name}",
|
||||
async () => results = await pair.Plugin.QueryAsync(query, token).ConfigureAwait(false));
|
||||
|
||||
token.ThrowIfCancellationRequested();
|
||||
|
|
|
|||
|
|
@ -11,12 +11,17 @@ using Flow.Launcher.Infrastructure.Logger;
|
|||
#pragma warning restore IDE0005
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
using Flow.Launcher.Plugin;
|
||||
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
|
||||
|
||||
namespace Flow.Launcher.Core.Plugin
|
||||
{
|
||||
public static class PluginsLoader
|
||||
{
|
||||
private static readonly string ClassName = nameof(PluginsLoader);
|
||||
|
||||
// We should not initialize API in static constructor because it will create another API instance
|
||||
private static IPublicAPI api = null;
|
||||
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||
|
||||
public static List<PluginPair> Plugins(List<PluginMetadata> metadatas, PluginsSettings settings)
|
||||
{
|
||||
var dotnetPlugins = DotNetPlugins(metadatas);
|
||||
|
|
@ -59,8 +64,7 @@ namespace Flow.Launcher.Core.Plugin
|
|||
|
||||
foreach (var metadata in metadatas)
|
||||
{
|
||||
var milliseconds = Stopwatch.Debug(
|
||||
$"|PluginsLoader.DotNetPlugins|Constructor init cost for {metadata.Name}", () =>
|
||||
var milliseconds = API.StopwatchLogDebug(ClassName, $"Constructor init cost for {metadata.Name}", () =>
|
||||
{
|
||||
Assembly assembly = null;
|
||||
IAsyncPlugin plugin = null;
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ using System.Threading;
|
|||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using Flow.Launcher.Infrastructure.Logger;
|
||||
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||
using Flow.Launcher.Infrastructure.Storage;
|
||||
using Flow.Launcher.Plugin;
|
||||
using SharpVectors.Converters;
|
||||
using SharpVectors.Renderers.Wpf;
|
||||
|
||||
|
|
@ -16,6 +17,12 @@ namespace Flow.Launcher.Infrastructure.Image
|
|||
{
|
||||
public static class ImageLoader
|
||||
{
|
||||
// We should not initialize API in static constructor because it will create another API instance
|
||||
private static IPublicAPI api = null;
|
||||
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
|
||||
|
||||
private static readonly string ClassName = nameof(ImageLoader);
|
||||
|
||||
private static readonly ImageCache ImageCache = new();
|
||||
private static SemaphoreSlim storageLock { get; } = new SemaphoreSlim(1, 1);
|
||||
private static BinaryStorage<List<(string, bool)>> _storage;
|
||||
|
|
@ -51,15 +58,14 @@ namespace Flow.Launcher.Infrastructure.Image
|
|||
|
||||
_ = Task.Run(async () =>
|
||||
{
|
||||
await Stopwatch.NormalAsync("|ImageLoader.Initialize|Preload images cost", async () =>
|
||||
await API.StopwatchLogInfoAsync(ClassName, "Preload images cost", async () =>
|
||||
{
|
||||
foreach (var (path, isFullImage) in usage)
|
||||
{
|
||||
await LoadAsync(path, isFullImage);
|
||||
}
|
||||
});
|
||||
Log.Info(
|
||||
$"|ImageLoader.Initialize|Number of preload images is <{ImageCache.CacheSize()}>, Images Number: {ImageCache.CacheSize()}, Unique Items {ImageCache.UniqueImagesInCache()}");
|
||||
API.LogInfo(ClassName, $"Number of preload images is <{ImageCache.CacheSize()}>, Images Number: {ImageCache.CacheSize()}, Unique Items {ImageCache.UniqueImagesInCache()}");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -75,7 +81,7 @@ namespace Flow.Launcher.Infrastructure.Image
|
|||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Log.Exception($"|ImageLoader.SaveAsync|Failed to save image cache to file", e);
|
||||
API.LogException(ClassName, "Failed to save image cache to file", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
@ -170,8 +176,8 @@ namespace Flow.Launcher.Infrastructure.Image
|
|||
}
|
||||
catch (System.Exception e2)
|
||||
{
|
||||
Log.Exception($"|ImageLoader.Load|Failed to get thumbnail for {path} on first try", e);
|
||||
Log.Exception($"|ImageLoader.Load|Failed to get thumbnail for {path} on second try", e2);
|
||||
API.LogException(ClassName, $"|ImageLoader.Load|Failed to get thumbnail for {path} on first try", e);
|
||||
API.LogException(ClassName, $"|ImageLoader.Load|Failed to get thumbnail for {path} on second try", e2);
|
||||
|
||||
ImageSource image = ImageCache[Constant.MissingImgIcon, false];
|
||||
ImageCache[path, false] = image;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Flow.Launcher.Infrastructure.Logger;
|
||||
|
||||
|
|
@ -7,8 +6,6 @@ namespace Flow.Launcher.Infrastructure
|
|||
{
|
||||
public static class Stopwatch
|
||||
{
|
||||
private static readonly Dictionary<string, long> Count = new Dictionary<string, long>();
|
||||
private static readonly object Locker = new object();
|
||||
/// <summary>
|
||||
/// This stopwatch will appear only in Debug mode
|
||||
/// </summary>
|
||||
|
|
@ -62,36 +59,5 @@ namespace Flow.Launcher.Infrastructure
|
|||
Log.Info(info);
|
||||
return milliseconds;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void StartCount(string name, Action action)
|
||||
{
|
||||
var stopWatch = new System.Diagnostics.Stopwatch();
|
||||
stopWatch.Start();
|
||||
action();
|
||||
stopWatch.Stop();
|
||||
var milliseconds = stopWatch.ElapsedMilliseconds;
|
||||
lock (Locker)
|
||||
{
|
||||
if (Count.ContainsKey(name))
|
||||
{
|
||||
Count[name] += milliseconds;
|
||||
}
|
||||
else
|
||||
{
|
||||
Count[name] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void EndCount()
|
||||
{
|
||||
foreach (var key in Count.Keys)
|
||||
{
|
||||
string info = $"{key} already cost {Count[key]}ms";
|
||||
Log.Debug(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -510,5 +510,31 @@ namespace Flow.Launcher.Plugin
|
|||
/// </param>
|
||||
/// <returns></returns>
|
||||
public Task UninstallPluginAsync(PluginMetadata pluginMetadata, bool removePluginSettings = false);
|
||||
|
||||
/// <summary>
|
||||
/// Log debug message of the time taken to execute a method
|
||||
/// Message will only be logged in Debug mode
|
||||
/// </summary>
|
||||
/// <returns>The time taken to execute the method in milliseconds</returns>
|
||||
public long StopwatchLogDebug(string className, string message, Action action, [CallerMemberName] string methodName = "");
|
||||
|
||||
/// <summary>
|
||||
/// Log debug message of the time taken to execute a method asynchronously
|
||||
/// Message will only be logged in Debug mode
|
||||
/// </summary>
|
||||
/// <returns>The time taken to execute the method in milliseconds</returns>
|
||||
public Task<long> StopwatchLogDebugAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "");
|
||||
|
||||
/// <summary>
|
||||
/// Log info message of the time taken to execute a method
|
||||
/// </summary>
|
||||
/// <returns>The time taken to execute the method in milliseconds</returns>
|
||||
public long StopwatchLogInfo(string className, string message, Action action, [CallerMemberName] string methodName = "");
|
||||
|
||||
/// <summary>
|
||||
/// Log info message of the time taken to execute a method asynchronously
|
||||
/// </summary>
|
||||
/// <returns>The time taken to execute the method in milliseconds</returns>
|
||||
public Task<long> StopwatchLogInfoAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ using Flow.Launcher.Plugin;
|
|||
using Flow.Launcher.ViewModel;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
|
||||
|
||||
namespace Flow.Launcher
|
||||
{
|
||||
|
|
@ -35,6 +34,8 @@ namespace Flow.Launcher
|
|||
|
||||
#region Private Fields
|
||||
|
||||
private static readonly string ClassName = nameof(App);
|
||||
|
||||
private static bool _disposed;
|
||||
private MainWindow _mainWindow;
|
||||
private readonly MainViewModel _mainVM;
|
||||
|
|
@ -136,7 +137,7 @@ namespace Flow.Launcher
|
|||
|
||||
private async void OnStartup(object sender, StartupEventArgs e)
|
||||
{
|
||||
await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
|
||||
await API.StopwatchLogInfoAsync(ClassName, "Startup cost", async () =>
|
||||
{
|
||||
// Because new message box api uses MessageBoxEx window,
|
||||
// if it is created and closed before main window is created, it will cause the application to exit.
|
||||
|
|
@ -313,7 +314,7 @@ namespace Flow.Launcher
|
|||
_disposed = true;
|
||||
}
|
||||
|
||||
Stopwatch.Normal("|App.Dispose|Dispose cost", () =>
|
||||
API.StopwatchLogInfo(ClassName, "Dispose cost", () =>
|
||||
{
|
||||
Log.Info("|App.Dispose|Begin Flow Launcher dispose ----------------------------------------------------");
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ using Flow.Launcher.Plugin.SharedCommands;
|
|||
using Flow.Launcher.ViewModel;
|
||||
using JetBrains.Annotations;
|
||||
using Squirrel;
|
||||
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
|
||||
|
||||
namespace Flow.Launcher
|
||||
{
|
||||
|
|
@ -431,6 +432,18 @@ namespace Flow.Launcher
|
|||
public Task UninstallPluginAsync(PluginMetadata pluginMetadata, bool removePluginSettings = false) =>
|
||||
PluginManager.UninstallPluginAsync(pluginMetadata, removePluginSettings);
|
||||
|
||||
public long StopwatchLogDebug(string className, string message, Action action, [CallerMemberName] string methodName = "") =>
|
||||
Stopwatch.Debug($"|{className}.{methodName}|{message}", action);
|
||||
|
||||
public Task<long> StopwatchLogDebugAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "") =>
|
||||
Stopwatch.DebugAsync($"|{className}.{methodName}|{message}", action);
|
||||
|
||||
public long StopwatchLogInfo(string className, string message, Action action, [CallerMemberName] string methodName = "") =>
|
||||
Stopwatch.Normal($"|{className}.{methodName}|{message}", action);
|
||||
|
||||
public Task<long> StopwatchLogInfoAsync(string className, string message, Func<Task> action, [CallerMemberName] string methodName = "") =>
|
||||
Stopwatch.NormalAsync($"|{className}.{methodName}|{message}", action);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
|
|
|||
|
|
@ -524,7 +524,7 @@ namespace Flow.Launcher.Plugin.Explorer.ViewModels
|
|||
}
|
||||
}
|
||||
|
||||
public int MaxResultLowerLimit => 100;
|
||||
public int MaxResultLowerLimit => 1;
|
||||
public int MaxResultUpperLimit => 100000;
|
||||
|
||||
public int MaxResult
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ using Flow.Launcher.Plugin.Program.Views.Models;
|
|||
using Flow.Launcher.Plugin.SharedCommands;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Path = System.IO.Path;
|
||||
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
|
||||
|
||||
namespace Flow.Launcher.Plugin.Program
|
||||
{
|
||||
|
|
@ -33,6 +32,8 @@ namespace Flow.Launcher.Plugin.Program
|
|||
|
||||
internal static PluginInitContext Context { get; private set; }
|
||||
|
||||
private static readonly string ClassName = nameof(Main);
|
||||
|
||||
private static readonly List<Result> emptyResults = new();
|
||||
|
||||
private static readonly MemoryCacheOptions cacheOptions = new() { SizeLimit = 1560 };
|
||||
|
|
@ -189,7 +190,7 @@ namespace Flow.Launcher.Plugin.Program
|
|||
|
||||
var _win32sCount = 0;
|
||||
var _uwpsCount = 0;
|
||||
await Stopwatch.NormalAsync("|Flow.Launcher.Plugin.Program.Main|Preload programs cost", async () =>
|
||||
await Context.API.StopwatchLogInfoAsync(ClassName, "Preload programs cost", async () =>
|
||||
{
|
||||
var pluginCacheDirectory = Context.CurrentPluginMetadata.PluginCacheDirectoryPath;
|
||||
FilesFolders.ValidateDirectory(pluginCacheDirectory);
|
||||
|
|
@ -256,6 +257,7 @@ namespace Flow.Launcher.Plugin.Program
|
|||
});
|
||||
Context.API.LogInfo(ClassName, $"Number of preload win32 programs <{_win32sCount}>");
|
||||
Context.API.LogInfo(ClassName, $"Number of preload uwps <{_uwpsCount}>");
|
||||
|
||||
var cacheEmpty = _win32sCount == 0 || _uwpsCount == 0;
|
||||
|
||||
if (cacheEmpty || _settings.LastIndexTime.AddHours(30) < DateTime.Now)
|
||||
|
|
@ -332,12 +334,12 @@ namespace Flow.Launcher.Plugin.Program
|
|||
{
|
||||
var win32Task = Task.Run(async () =>
|
||||
{
|
||||
await Stopwatch.NormalAsync("|Flow.Launcher.Plugin.Program.Main|Win32Program index cost", IndexWin32ProgramsAsync);
|
||||
await Context.API.StopwatchLogInfoAsync(ClassName, "Win32Program index cost", IndexWin32ProgramsAsync);
|
||||
});
|
||||
|
||||
var uwpTask = Task.Run(async () =>
|
||||
{
|
||||
await Stopwatch.NormalAsync("|Flow.Launcher.Plugin.Program.Main|UWPProgram index cost", IndexUwpProgramsAsync);
|
||||
await Context.API.StopwatchLogInfoAsync(ClassName, "UWPProgram index cost", IndexUwpProgramsAsync);
|
||||
});
|
||||
|
||||
await Task.WhenAll(win32Task, uwpTask).ConfigureAwait(false);
|
||||
|
|
|
|||
Loading…
Reference in a new issue