Skip to content
Closed
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
66 changes: 62 additions & 4 deletions Plugins/Flow.Launcher.Plugin.Program/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@

internal static PluginInitContext Context { get; private set; }

private static Task _indexingTask;
private static readonly object _indexingTaskLock = new();

private static readonly List<Result> emptyResults = [];

private static readonly MemoryCacheOptions cacheOptions = new() { SizeLimit = 1560 };
Expand All @@ -40,10 +43,10 @@
{
"uninst.exe",
"unins000.exe",
"uninst000.exe",

Check warning on line 46 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`uninst` is not a recognized word. (unrecognized-spelling)

Check warning on line 46 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`uninst` is not a recognized word. (unrecognized-spelling)
"uninstall.exe"
};
private static readonly string[] commonUninstallerPrefixs =

Check warning on line 49 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Uninstaller` is not a recognized word. (unrecognized-spelling)

Check warning on line 49 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Uninstaller` is not a recognized word. (unrecognized-spelling)
{
"uninstall",//en
"卸载",//zh-cn
Expand All @@ -59,9 +62,9 @@
"삭제",//ko
"деинсталирај",//sr
"desinstalar",//pt-pt
"desinstalar",//pt-br

Check warning on line 65 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`desinstalar` is not a recognized word. (unrecognized-spelling)

Check warning on line 65 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`desinstalar` is not a recognized word. (unrecognized-spelling)
"desinstalar",//es

Check warning on line 66 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`desinstalar` is not a recognized word. (unrecognized-spelling)

Check warning on line 66 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`desinstalar` is not a recognized word. (unrecognized-spelling)
"desinstalar",//es-419

Check warning on line 67 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`desinstalar` is not a recognized word. (unrecognized-spelling)

Check warning on line 67 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`desinstalar` is not a recognized word. (unrecognized-spelling)
"disinstallare",//it
"avinstallere",//nb-NO
"odinštalovať",//sk
Expand All @@ -71,13 +74,38 @@
"gỡ bỏ",//vi-vn
"הסרה"//he
};
private const string ExeUninstallerSuffix = ".exe";

Check warning on line 77 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Uninstaller` is not a recognized word. (unrecognized-spelling)

Check warning on line 77 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Uninstaller` is not a recognized word. (unrecognized-spelling)
private const string InkUninstallerSuffix = ".lnk";

Check warning on line 78 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Uninstaller` is not a recognized word. (unrecognized-spelling)

Check warning on line 78 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Uninstaller` is not a recognized word. (unrecognized-spelling)

private static readonly string WindowsAppPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "WindowsApps");

public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
{
// Wait for initial indexing to complete if it's still running
Task indexingTask;
lock (_indexingTaskLock)
{
indexingTask = _indexingTask;
}

if (indexingTask != null && !indexingTask.IsCompleted)
{
try
{
// Wait for indexing with a reasonable timeout to avoid blocking queries indefinitely
await Task.WhenAny(indexingTask, Task.Delay(TimeSpan.FromSeconds(30), token)).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
// Query was cancelled, return empty results
return emptyResults.ToList();
}
catch (Exception e)
{
Context.API.LogException(ClassName, "Error waiting for indexing to complete", e);
}
}

var result = await cache.GetOrCreateAsync(query.Search, async entry =>
{
var resultList = await Task.Run(async () =>
Expand Down Expand Up @@ -127,7 +155,7 @@
return result;
}

private bool HideUninstallersFilter(IProgram program)

Check warning on line 158 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Uninstallers` is not a recognized word. (unrecognized-spelling)

Check warning on line 158 in Plugins/Flow.Launcher.Plugin.Program/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Uninstallers` is not a recognized word. (unrecognized-spelling)
{
if (!_settings.HideUninstallers) return true;
if (program is not Win32 win32) return true;
Expand Down Expand Up @@ -277,11 +305,21 @@

if (cacheEmpty || _settings.LastIndexTime.AddHours(30) < DateTime.Now)
{
_ = Task.Run(async () =>
lock (_indexingTaskLock)
{
await IndexProgramsAsync().ConfigureAwait(false);
WatchProgramUpdate();
});
_indexingTask = Task.Run(async () =>
{
try
{
await IndexProgramsAsync().ConfigureAwait(false);
WatchProgramUpdate();
}
catch (Exception e)
{
Context.API.LogException(ClassName, "Failed to complete program indexing", e);
}
});
}
}
else
{
Expand Down Expand Up @@ -483,6 +521,26 @@

public void Dispose()
{
// Wait for indexing to complete before disposing
Task indexingTask;
lock (_indexingTaskLock)
{
indexingTask = _indexingTask;
}

if (indexingTask != null && !indexingTask.IsCompleted)
{
try
{
// Wait for indexing to complete with a reasonable timeout
indexingTask.Wait(TimeSpan.FromSeconds(10));
}
catch (Exception e)
{
Context?.API?.LogException(ClassName, "Error waiting for indexing during dispose", e);
}
}

Win32.Dispose();
}
}
Expand Down
Loading