mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Improve semaphore lock handling and code robustness
Added `lockAcquired` flags in `PluginsManifest.cs` and `Main.cs` to ensure semaphore locks are only released if successfully acquired, preventing potential runtime errors. Updated `finally` blocks to conditionally release locks based on these flags. Removed redundant cancellation check in `EverythingAPI.cs` to simplify code, assuming cancellation is handled elsewhere. These changes enhance reliability and maintainability of the codebase.
This commit is contained in:
parent
05c8dd2fe1
commit
2adbc334a2
3 changed files with 18 additions and 5 deletions
|
|
@ -26,9 +26,11 @@ namespace Flow.Launcher.Core.ExternalPlugins
|
|||
|
||||
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)
|
||||
{
|
||||
|
|
@ -64,7 +66,8 @@ namespace Flow.Launcher.Core.ExternalPlugins
|
|||
}
|
||||
finally
|
||||
{
|
||||
manifestUpdateLock.Release();
|
||||
// Only release the lock if it was acquired
|
||||
if (lockAcquired) manifestUpdateLock.Release();
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -133,8 +133,6 @@ namespace Flow.Launcher.Plugin.Explorer.Search.Everything
|
|||
EverythingApiDllImport.Everything_SetRequestFlags(EVERYTHING_REQUEST_FULL_PATH_AND_FILE_NAME);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (token.IsCancellationRequested) yield break;
|
||||
|
||||
if (!EverythingApiDllImport.Everything_QueryW(true))
|
||||
|
|
|
|||
|
|
@ -86,29 +86,41 @@ namespace Flow.Launcher.Plugin.Program
|
|||
{
|
||||
// Preparing win32 programs
|
||||
List<Win32> win32s;
|
||||
bool win32LockAcquired = false;
|
||||
try
|
||||
{
|
||||
await _win32sLock.WaitAsync(token);
|
||||
win32LockAcquired = true;
|
||||
win32s = [.. _win32s];
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
return emptyResults;
|
||||
}
|
||||
_win32sLock.Release();
|
||||
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;
|
||||
}
|
||||
_uwpsLock.Release();
|
||||
finally
|
||||
{
|
||||
// Only release the lock if it was acquired
|
||||
if (uwpsLockAcquired) _uwpsLock.Release();
|
||||
}
|
||||
|
||||
// Start querying programs
|
||||
try
|
||||
|
|
|
|||
Loading…
Reference in a new issue