Skip to content
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

Fix Possible Plugin Initialization Issue #3303

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 3 additions & 4 deletions Flow.Launcher.Core/Plugin/PluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ public static async Task InitializePluginsAsync()
{
var failedPlugins = new ConcurrentQueue<PluginPair>();

var InitTasks = AllPlugins.Select(pair => Task.Run(async delegate
// Some plugins should not be initialized in task, so we cannot use Task.WhenAll here
foreach (var pair in AllPlugins)
{
try
{
Expand All @@ -182,9 +183,7 @@ public static async Task InitializePluginsAsync()
pair.Metadata.Disabled = true;
failedPlugins.Enqueue(pair);
}
}));

await Task.WhenAll(InitTasks);
}

_contextMenuPlugins = GetPluginsForInterface<IContextMenu>();
foreach (var plugin in AllPlugins)
Expand Down
7 changes: 6 additions & 1 deletion Flow.Launcher.Plugin/Interfaces/IPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public interface IPlugin : IAsyncPlugin
/// <param name="context"></param>
void Init(PluginInitContext context);

Task IAsyncPlugin.InitAsync(PluginInitContext context) => Task.Run(() => Init(context));
async Task IAsyncPlugin.InitAsync(PluginInitContext context)
{
// Some plugins should not be initialized in task
Init(context);
await Task.CompletedTask;
}

Task<List<Result>> IAsyncPlugin.QueryAsync(Query query, CancellationToken token) => Task.Run(() => Query(query));
}
Expand Down
Loading