Skip to content

Test #3508 #3512

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Flow.Launcher.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading;
using System.Threading.Tasks;
using CommunityToolkit.Mvvm.DependencyInjection;
using Droplex;
using Flow.Launcher.Core.ExternalPlugins;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.UserSettings;
Expand Down Expand Up @@ -276,27 +277,44 @@ public static ICollection<PluginPair> ValidPluginsForQuery(Query query)

public static async Task<List<Result>> QueryForPluginAsync(PluginPair pair, Query query, CancellationToken token)
{
API.LogDebug(ClassName, $"a");

var results = new List<Result>();
var metadata = pair.Metadata;

try
{
API.LogDebug(ClassName, $"b");

var milliseconds = await API.StopwatchLogDebugAsync(ClassName, $"Cost for {metadata.Name}",
async () => results = await pair.Plugin.QueryAsync(query, token).ConfigureAwait(false));

API.LogDebug(ClassName, $"c");

token.ThrowIfCancellationRequested();

API.LogDebug(ClassName, $"d");

if (results == null)
return null;

API.LogDebug(ClassName, $"e");

UpdatePluginMetadata(results, metadata, query);

API.LogDebug(ClassName, $"f");

metadata.QueryCount += 1;
metadata.AvgQueryTime =
metadata.QueryCount == 1 ? milliseconds : (metadata.AvgQueryTime + milliseconds) / 2;
token.ThrowIfCancellationRequested();

API.LogDebug(ClassName, $"g");
}
catch (OperationCanceledException)
{
// null will be fine since the results will only be added into queue if the token hasn't been cancelled
API.LogDebug(ClassName, $"h");
return null;
}
catch (Exception e)
Expand Down
12 changes: 12 additions & 0 deletions Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,14 +1341,22 @@ async Task QueryTaskAsync(PluginPair plugin, CancellationToken token)
if (token.IsCancellationRequested) return;
}

App.API.LogDebug(ClassName, $"1");

// Since it is wrapped within a ThreadPool Thread, the synchronous context is null
// Task.Yield will force it to run in ThreadPool
await Task.Yield();

App.API.LogDebug(ClassName, $"2");

var results = await PluginManager.QueryForPluginAsync(plugin, query, token);

App.API.LogDebug(ClassName, $"3");

if (token.IsCancellationRequested) return;

App.API.LogDebug(ClassName, $"4");

IReadOnlyList<Result> resultsCopy;
if (results == null)
{
Expand All @@ -1360,6 +1368,8 @@ async Task QueryTaskAsync(PluginPair plugin, CancellationToken token)
resultsCopy = DeepCloneResults(results, token);
}

App.API.LogDebug(ClassName, $"5");

foreach (var result in resultsCopy)
{
if (string.IsNullOrEmpty(result.BadgeIcoPath))
Expand All @@ -1368,6 +1378,8 @@ async Task QueryTaskAsync(PluginPair plugin, CancellationToken token)
}
}

App.API.LogDebug(ClassName, $"6");

if (token.IsCancellationRequested) return;

App.API.LogDebug(ClassName, $"Update results for plugin <{plugin.Metadata.Name}>");
Expand Down
Loading