Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,14 @@

public static async ValueTask<bool> IsEverythingRunningAsync(CancellationToken token = default)
{
await _semaphore.WaitAsync(token);
// We do not directly pass token here, but we check IsCancellationRequested inside the lock
// So that it will not raise OperationCanceledException, which is not expected by the caller.
await _semaphore.WaitAsync();

try
{
EverythingApiDllImport.Everything_GetMajorVersion();
if (token.IsCancellationRequested) return false;
_ = EverythingApiDllImport.Everything_GetMajorVersion();
var result = EverythingApiDllImport.Everything_GetLastError() != StateCode.IPCError;
return result;
}
Expand All @@ -77,8 +80,7 @@
if (option.MaxCount < 0)
throw new ArgumentOutOfRangeException(nameof(option.MaxCount), option.MaxCount, "MaxCount must be greater than or equal to 0");

await _semaphore.WaitAsync(token);

await _semaphore.WaitAsync();

try
{
Expand Down Expand Up @@ -130,20 +132,20 @@
yield break;
}

for (var idx = 0; idx < EverythingApiDllImport.Everything_GetNumResults(); ++idx)

Check warning on line 135 in Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

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

Check warning on line 135 in Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`idx` is not a recognized word. (unrecognized-spelling)
{
if (token.IsCancellationRequested)
{
yield break;
}

EverythingApiDllImport.Everything_GetResultFullPathNameW(idx, buffer, BufferSize);

Check warning on line 142 in Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

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

var result = new SearchResult
{
// todo the types are wrong. Everything expects uint everywhere, but we send int just above/below. how to fix? Is EverythingApiDllImport autogenerated or handmade?
FullPath = buffer.ToString(),
Type = EverythingApiDllImport.Everything_IsFolderResult(idx) ? ResultType.Folder :

Check warning on line 148 in Plugins/Flow.Launcher.Plugin.Explorer/Search/Everything/EverythingAPI.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`idx` is not a recognized word. (unrecognized-spelling)
EverythingApiDllImport.Everything_IsFileResult(idx) ? ResultType.File :
ResultType.Volume,
Score = (int)EverythingApiDllImport.Everything_GetResultRunCount( (uint)idx)
Expand Down
64 changes: 52 additions & 12 deletions Plugins/Flow.Launcher.Plugin.Program/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,21 @@

internal static PluginInitContext Context { get; private set; }

private static readonly Lock _lastIndexTimeLock = new();

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

private static readonly MemoryCacheOptions cacheOptions = new() { SizeLimit = 1560 };
private static MemoryCache cache = new(cacheOptions);

private static readonly string[] commonUninstallerNames =

Check warning on line 41 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)
{
"uninst.exe",
"unins000.exe",
"uninst000.exe",

Check warning on line 45 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 48 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 +61,9 @@
"삭제",//ko
"деинсталирај",//sr
"desinstalar",//pt-pt
"desinstalar",//pt-br

Check warning on line 64 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 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-419

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)
"disinstallare",//it
"avinstallere",//nb-NO
"odinštalovať",//sk
Expand All @@ -82,8 +84,37 @@
{
var resultList = await Task.Run(async () =>
{
await _win32sLock.WaitAsync(token);
await _uwpsLock.WaitAsync(token);
// We do not directly pass token here, but we check IsCancellationRequested inside the lock
// So that it will not raise OperationCanceledException, which is not expected by the caller.
Context.API.LogDebug(ClassName, "Preparing win32 programs");
List<Win32> win32s;
await _win32sLock.WaitAsync();
try
{
win32s = [.. _win32s];
if (token.IsCancellationRequested) return emptyResults;
}
finally
{
_win32sLock.Release();
}

// We do not directly pass token here, but we check IsCancellationRequested inside the lock
// So that it will not raise OperationCanceledException, which is not expected by the caller.
Context.API.LogDebug(ClassName, "Preparing UWP programs");
List<UWPApp> uwps;
await _uwpsLock.WaitAsync();
try
{
uwps = [.. _uwps];
if (token.IsCancellationRequested) return emptyResults;
}
finally
{
_uwpsLock.Release();
}

Context.API.LogDebug(ClassName, "Start querying programs");
try
{
// Collect all UWP Windows app directories
Expand All @@ -94,8 +125,8 @@
.Distinct(StringComparer.OrdinalIgnoreCase)
.ToArray() : null;

return _win32s.Cast<IProgram>()
.Concat(_uwps)
return win32s.Cast<IProgram>()
.Concat(uwps)
.AsParallel()
.WithCancellation(token)
.Where(HideUninstallersFilter)
Expand All @@ -109,11 +140,6 @@
{
return emptyResults;
}
finally
{
_uwpsLock.Release();
_win32sLock.Release();
}
}, token);

resultList = resultList.Count != 0 ? resultList : emptyResults;
Expand Down Expand Up @@ -275,7 +301,12 @@

var cacheEmpty = _win32sCount == 0 || _uwpsCount == 0;

if (cacheEmpty || _settings.LastIndexTime.AddHours(30) < DateTime.Now)
bool needReindex;
lock (_lastIndexTimeLock)
{
needReindex = _settings.LastIndexTime.AddHours(30) < DateTime.Now;
}
if (cacheEmpty || needReindex)
{
_ = Task.Run(async () =>
{
Expand All @@ -298,6 +329,7 @@
public static async Task IndexWin32ProgramsAsync()
{
await _win32sLock.WaitAsync();
Context.API.LogDebug(ClassName, "Start indexing Win32 programs");
try
{
var win32S = Win32.All(_settings);
Expand All @@ -308,7 +340,10 @@
}
ResetCache();
await Context.API.SaveCacheBinaryStorageAsync<List<Win32>>(Win32CacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath);
_settings.LastIndexTime = DateTime.Now;
lock (_lastIndexTimeLock)
{
_settings.LastIndexTime = DateTime.Now;
}
}
catch (Exception e)
{
Expand All @@ -323,6 +358,7 @@
public static async Task IndexUwpProgramsAsync()
{
await _uwpsLock.WaitAsync();
Context.API.LogDebug(ClassName, "Start indexing Uwp programs");
try
{
var uwps = UWPPackage.All(_settings);
Expand All @@ -333,7 +369,10 @@
}
ResetCache();
await Context.API.SaveCacheBinaryStorageAsync<List<UWPApp>>(UwpCacheName, Context.CurrentPluginMetadata.PluginCacheDirectoryPath);
_settings.LastIndexTime = DateTime.Now;
lock (_lastIndexTimeLock)
{
_settings.LastIndexTime = DateTime.Now;
}
}
catch (Exception e)
{
Expand All @@ -357,6 +396,7 @@
await Context.API.StopwatchLogInfoAsync(ClassName, "UWPProgram index cost", IndexUwpProgramsAsync);
});

Context.API.LogDebug(ClassName, "Start indexing");
await Task.WhenAll(win32Task, uwpTask).ConfigureAwait(false);
}

Expand Down
Loading