@@ -31,7 +31,7 @@ public class Main : ISettingProvider, IAsyncPlugin, IPluginI18n, IContextMenu, I
3131
3232 internal static PluginInitContext Context { get ; private set ; }
3333
34- private static readonly List < Result > emptyResults = new ( ) ;
34+ private static readonly List < Result > emptyResults = [ ] ;
3535
3636 private static readonly MemoryCacheOptions cacheOptions = new ( ) { SizeLimit = 1560 } ;
3737 private static MemoryCache cache = new ( cacheOptions ) ;
@@ -84,7 +84,6 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
8484 {
8585 await _win32sLock . WaitAsync ( token ) ;
8686 await _uwpsLock . WaitAsync ( token ) ;
87-
8887 try
8988 {
9089 // Collect all UWP Windows app directories
@@ -117,7 +116,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
117116 }
118117 } , token ) ;
119118
120- resultList = resultList . Any ( ) ? resultList : emptyResults ;
119+ resultList = resultList . Count != 0 ? resultList : emptyResults ;
121120
122121 entry . SetSize ( resultList . Count ) ;
123122 entry . SetSlidingExpiration ( TimeSpan . FromHours ( 8 ) ) ;
@@ -250,14 +249,26 @@ static void MoveFile(string sourcePath, string destinationPath)
250249 }
251250
252251 await _win32sLock . WaitAsync ( ) ;
253- _win32s = await context . API . LoadCacheBinaryStorageAsync ( Win32CacheName , pluginCacheDirectory , new List < Win32 > ( ) ) ;
254- _win32sCount = _win32s . Count ;
255- _win32sLock . Release ( ) ;
252+ try
253+ {
254+ _win32s = await context . API . LoadCacheBinaryStorageAsync ( Win32CacheName , pluginCacheDirectory , new List < Win32 > ( ) ) ;
255+ _win32sCount = _win32s . Count ;
256+ }
257+ finally
258+ {
259+ _win32sLock . Release ( ) ;
260+ }
256261
257262 await _uwpsLock . WaitAsync ( ) ;
258- _uwps = await context . API . LoadCacheBinaryStorageAsync ( UwpCacheName , pluginCacheDirectory , new List < UWPApp > ( ) ) ;
259- _uwpsCount = _uwps . Count ;
260- _uwpsLock . Release ( ) ;
263+ try
264+ {
265+ _uwps = await context . API . LoadCacheBinaryStorageAsync ( UwpCacheName , pluginCacheDirectory , new List < UWPApp > ( ) ) ;
266+ _uwpsCount = _uwps . Count ;
267+ }
268+ finally
269+ {
270+ _uwpsLock . Release ( ) ;
271+ }
261272 } ) ;
262273 Context . API . LogInfo ( ClassName , $ "Number of preload win32 programs <{ _win32sCount } >") ;
263274 Context . API . LogInfo ( ClassName , $ "Number of preload uwps <{ _uwpsCount } >") ;
@@ -407,38 +418,46 @@ private static async Task DisableProgramAsync(IProgram programToDelete)
407418 return ;
408419
409420 await _uwpsLock . WaitAsync ( ) ;
410- if ( _uwps . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) )
421+ var reindexUwps = true ;
422+ try
411423 {
424+ reindexUwps = _uwps . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
412425 var program = _uwps . First ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
413426 program . Enabled = false ;
414427 _settings . DisabledProgramSources . Add ( new ProgramSource ( program ) ) ;
428+ }
429+ finally
430+ {
415431 _uwpsLock . Release ( ) ;
432+ }
416433
417- // Reindex UWP programs
434+ // Reindex UWP programs
435+ if ( reindexUwps )
436+ {
418437 _ = Task . Run ( IndexUwpProgramsAsync ) ;
419438 return ;
420439 }
421- else
422- {
423- _uwpsLock . Release ( ) ;
424- }
425440
426441 await _win32sLock . WaitAsync ( ) ;
427- if ( _win32s . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) )
442+ var reindexWin32s = true ;
443+ try
428444 {
445+ reindexWin32s = _win32s . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
429446 var program = _win32s . First ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
430447 program . Enabled = false ;
431448 _settings . DisabledProgramSources . Add ( new ProgramSource ( program ) ) ;
449+ }
450+ finally
451+ {
432452 _win32sLock . Release ( ) ;
453+ }
433454
434- // Reindex Win32 programs
455+ // Reindex Win32 programs
456+ if ( reindexWin32s )
457+ {
435458 _ = Task . Run ( IndexWin32ProgramsAsync ) ;
436459 return ;
437460 }
438- else
439- {
440- _win32sLock . Release ( ) ;
441- }
442461 }
443462
444463 public static void StartProcess ( Func < ProcessStartInfo , Process > runProcess , ProcessStartInfo info )
0 commit comments