Skip to content
Merged
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
9 changes: 8 additions & 1 deletion Flow.Launcher.Core/ExternalPlugins/PluginsManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ public static class PluginsManifest

public static async Task<bool> UpdateManifestAsync(bool usePrimaryUrlOnly = false, CancellationToken token = default)
{
bool lockAcquired = false;
try
{
await manifestUpdateLock.WaitAsync(token).ConfigureAwait(false);
lockAcquired = true;

if (UserPlugins == null || usePrimaryUrlOnly || DateTime.Now.Subtract(lastFetchedAt) >= fetchTimeout)
{
Expand All @@ -54,13 +56,18 @@ public static async Task<bool> UpdateManifestAsync(bool usePrimaryUrlOnly = fals
return true;
}
}
catch (OperationCanceledException)
{
// Ignored
}
catch (Exception e)
{
PublicApi.Instance.LogException(ClassName, "Http request failed", e);
}
finally
{
manifestUpdateLock.Release();
// Only release the lock if it was acquired
if (lockAcquired) manifestUpdateLock.Release();
}

return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,18 @@

public static async ValueTask<bool> IsEverythingRunningAsync(CancellationToken token = default)
{
await _semaphore.WaitAsync(token);
try
{
await _semaphore.WaitAsync(token);
}
catch (OperationCanceledException)
{
return false;
}

try
{
EverythingApiDllImport.Everything_GetMajorVersion();
_ = EverythingApiDllImport.Everything_GetMajorVersion();
var result = EverythingApiDllImport.Everything_GetLastError() != StateCode.IPCError;
return result;
}
Expand All @@ -77,8 +84,14 @@
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);

try
{
await _semaphore.WaitAsync(token);
}
catch (OperationCanceledException)
{
yield break;
}

try
{
Expand Down Expand Up @@ -120,8 +133,6 @@
EverythingApiDllImport.Everything_SetRequestFlags(EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME);
}



if (token.IsCancellationRequested) yield break;

if (!EverythingApiDllImport.Everything_QueryW(true))
Expand All @@ -130,20 +141,20 @@
yield break;
}

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

Check warning on line 144 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 144 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 151 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 157 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
69 changes: 57 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,45 @@
{
var resultList = await Task.Run(async () =>
{
await _win32sLock.WaitAsync(token);
await _uwpsLock.WaitAsync(token);
// Preparing win32 programs
List<Win32> win32s;
bool win32LockAcquired = false;
try
{
await _win32sLock.WaitAsync(token);
win32LockAcquired = true;
win32s = [.. _win32s];
}
catch (OperationCanceledException)
{
return emptyResults;
}
finally
{
// Only release the lock if it was acquired
if (win32LockAcquired) _win32sLock.Release();
}

// Preparing UWP programs
List<UWPApp> uwps;
bool uwpsLockAcquired = false;
try
{
await _uwpsLock.WaitAsync(token);
uwpsLockAcquired = true;
uwps = [.. _uwps];
}
catch (OperationCanceledException)
{
return emptyResults;
}
finally
{
// Only release the lock if it was acquired
if (uwpsLockAcquired) _uwpsLock.Release();
}

// Start querying programs
try
{
// Collect all UWP Windows app directories
Expand All @@ -94,8 +133,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 +148,6 @@
{
return emptyResults;
}
finally
{
_uwpsLock.Release();
_win32sLock.Release();
}
}, token);

resultList = resultList.Count != 0 ? resultList : emptyResults;
Expand Down Expand Up @@ -275,7 +309,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 Down Expand Up @@ -308,7 +347,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 @@ -333,7 +375,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 Down
Loading