@@ -31,7 +31,7 @@ public class Main : ISettingProvider, IAsyncPlugin, IPluginI18n, IContextMenu, I
31
31
32
32
internal static PluginInitContext Context { get ; private set ; }
33
33
34
- private static readonly List < Result > emptyResults = new ( ) ;
34
+ private static readonly List < Result > emptyResults = [ ] ;
35
35
36
36
private static readonly MemoryCacheOptions cacheOptions = new ( ) { SizeLimit = 1560 } ;
37
37
private static MemoryCache cache = new ( cacheOptions ) ;
@@ -84,7 +84,6 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
84
84
{
85
85
await _win32sLock . WaitAsync ( token ) ;
86
86
await _uwpsLock . WaitAsync ( token ) ;
87
-
88
87
try
89
88
{
90
89
// Collect all UWP Windows app directories
@@ -117,7 +116,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
117
116
}
118
117
} , token ) ;
119
118
120
- resultList = resultList . Any ( ) ? resultList : emptyResults ;
119
+ resultList = resultList . Count != 0 ? resultList : emptyResults ;
121
120
122
121
entry . SetSize ( resultList . Count ) ;
123
122
entry . SetSlidingExpiration ( TimeSpan . FromHours ( 8 ) ) ;
@@ -250,14 +249,26 @@ static void MoveFile(string sourcePath, string destinationPath)
250
249
}
251
250
252
251
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
+ }
256
261
257
262
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
+ }
261
272
} ) ;
262
273
Context . API . LogInfo ( ClassName , $ "Number of preload win32 programs <{ _win32sCount } >") ;
263
274
Context . API . LogInfo ( ClassName , $ "Number of preload uwps <{ _uwpsCount } >") ;
@@ -408,38 +419,47 @@ private static async Task DisableProgramAsync(IProgram programToDelete)
408
419
return ;
409
420
410
421
await _uwpsLock . WaitAsync ( ) ;
411
- if ( _uwps . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) )
422
+ var reindexUwps = true ;
423
+ try
412
424
{
425
+ reindexUwps = _uwps . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
413
426
var program = _uwps . First ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
414
427
program . Enabled = false ;
415
428
_settings . DisabledProgramSources . Add ( new ProgramSource ( program ) ) ;
429
+ }
430
+ finally
431
+ {
416
432
_uwpsLock . Release ( ) ;
433
+ }
417
434
418
- // Reindex UWP programs
435
+ // Reindex UWP programs
436
+ if ( reindexUwps )
437
+ {
419
438
_ = Task . Run ( IndexUwpProgramsAsync ) ;
420
439
return ;
421
440
}
422
- else
423
- {
424
- _uwpsLock . Release ( ) ;
425
- }
426
441
427
442
await _win32sLock . WaitAsync ( ) ;
428
- if ( _win32s . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) )
443
+ var reindexWin32s = true ;
444
+ try
429
445
{
446
+ reindexWin32s = _win32s . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
430
447
var program = _win32s . First ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
431
448
program . Enabled = false ;
432
449
_settings . DisabledProgramSources . Add ( new ProgramSource ( program ) ) ;
433
450
_win32sLock . Release ( ) ;
434
-
435
- // Reindex Win32 programs
436
- _ = Task . Run ( IndexWin32ProgramsAsync ) ;
437
- return ;
438
451
}
439
- else
452
+ finally
440
453
{
441
454
_win32sLock . Release ( ) ;
442
455
}
456
+
457
+ // Reindex Win32 programs
458
+ if ( reindexWin32s )
459
+ {
460
+ _ = Task . Run ( IndexWin32ProgramsAsync ) ;
461
+ return ;
462
+ }
443
463
}
444
464
445
465
public static void StartProcess ( Func < ProcessStartInfo , Process > runProcess , ProcessStartInfo info )
0 commit comments