@@ -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 } >") ;
@@ -408,38 +419,46 @@ private static async Task DisableProgramAsync(IProgram programToDelete)
408419 return ;
409420
410421 await _uwpsLock . WaitAsync ( ) ;
411- if ( _uwps . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) )
422+ var reindexUwps = true ;
423+ try
412424 {
425+ reindexUwps = _uwps . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
413426 var program = _uwps . First ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
414427 program . Enabled = false ;
415428 _settings . DisabledProgramSources . Add ( new ProgramSource ( program ) ) ;
429+ }
430+ finally
431+ {
416432 _uwpsLock . Release ( ) ;
433+ }
417434
418- // Reindex UWP programs
435+ // Reindex UWP programs
436+ if ( reindexUwps )
437+ {
419438 _ = Task . Run ( IndexUwpProgramsAsync ) ;
420439 return ;
421440 }
422- else
423- {
424- _uwpsLock . Release ( ) ;
425- }
426441
427442 await _win32sLock . WaitAsync ( ) ;
428- if ( _win32s . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) )
443+ var reindexWin32s = true ;
444+ try
429445 {
446+ reindexWin32s = _win32s . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
430447 var program = _win32s . First ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
431448 program . Enabled = false ;
432449 _settings . DisabledProgramSources . Add ( new ProgramSource ( program ) ) ;
450+ }
451+ finally
452+ {
433453 _win32sLock . Release ( ) ;
454+ }
434455
435- // Reindex Win32 programs
456+ // Reindex Win32 programs
457+ if ( reindexWin32s )
458+ {
436459 _ = Task . Run ( IndexWin32ProgramsAsync ) ;
437460 return ;
438461 }
439- else
440- {
441- _win32sLock . Release ( ) ;
442- }
443462 }
444463
445464 public static void StartProcess ( Func < ProcessStartInfo , Process > runProcess , ProcessStartInfo info )
0 commit comments