Skip to content

Commit e59902c

Browse files
committed
If the list is not initialized, we need to wait for the list to be refreshed before querying
1 parent 17aab46 commit e59902c

File tree

1 file changed

+16
-19
lines changed
  • Plugins/Flow.Launcher.Plugin.BrowserBookmark

1 file changed

+16
-19
lines changed

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

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
namespace Flow.Launcher.Plugin.BrowserBookmark;
1414

15-
public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContextMenu, IDisposable
15+
public class Main : ISettingProvider, IAsyncPlugin, IReloadable, IPluginI18n, IContextMenu, IDisposable
1616
{
1717
private static readonly string ClassName = nameof(Main);
1818

@@ -34,7 +34,7 @@ public class Main : ISettingProvider, IPlugin, IReloadable, IPluginI18n, IContex
3434

3535
private static CancellationTokenSource _debounceTokenSource;
3636

37-
public void Init(PluginInitContext context)
37+
public async Task InitAsync(PluginInitContext context)
3838
{
3939
_instance = this;
4040
_context = context;
@@ -46,6 +46,7 @@ public void Init(PluginInitContext context)
4646

4747
// Start loading bookmarks asynchronously without blocking Init
4848
_ = LoadBookmarksInBackgroundAsync();
49+
await Task.CompletedTask;
4950
}
5051

5152
private async Task LoadBookmarksInBackgroundAsync()
@@ -83,33 +84,29 @@ private async Task LoadBookmarksInBackgroundAsync()
8384
}
8485
}
8586

86-
public List<Result> Query(Query query)
87+
public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
8788
{
88-
// Immediately return if the initial load is not complete, providing feedback to the user.
8989
if (!_isInitialized)
9090
{
91-
var initializingTitle = _context.API.GetTranslation("flowlauncher_plugin_browserbookmark_plugin_name");
92-
var initializingSubTitle = "Plugin is initializing, please try again in a few seconds";
91+
// If the list is not initialized, we need to wait for the list to be refreshed before querying
92+
await _initializationSemaphore.WaitAsync(token);
9393
try
9494
{
95-
initializingSubTitle = _context.API.GetTranslation("flowlauncher_plugin_browserbookmark_plugin_initializing");
95+
return QueryResults(query);
9696
}
97-
catch (KeyNotFoundException)
97+
finally
9898
{
99-
// Ignoring since not all language files will have this key.
99+
_initializationSemaphore.Release();
100100
}
101-
102-
return new List<Result>
103-
{
104-
new()
105-
{
106-
Title = initializingTitle,
107-
SubTitle = initializingSubTitle,
108-
IcoPath = DefaultIconPath
109-
}
110-
};
111101
}
102+
else
103+
{
104+
return QueryResults(query);
105+
}
106+
}
112107

108+
private static List<Result> QueryResults(Query query)
109+
{
113110
string param = query.Search.TrimStart();
114111
bool topResults = string.IsNullOrEmpty(param);
115112

0 commit comments

Comments
 (0)