@@ -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 } >") ;
@@ -407,38 +418,46 @@ private static async Task DisableProgramAsync(IProgram programToDelete)
407
418
return ;
408
419
409
420
await _uwpsLock . WaitAsync ( ) ;
410
- if ( _uwps . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) )
421
+ var reindexUwps = true ;
422
+ try
411
423
{
424
+ reindexUwps = _uwps . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
412
425
var program = _uwps . First ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
413
426
program . Enabled = false ;
414
427
_settings . DisabledProgramSources . Add ( new ProgramSource ( program ) ) ;
428
+ }
429
+ finally
430
+ {
415
431
_uwpsLock . Release ( ) ;
432
+ }
416
433
417
- // Reindex UWP programs
434
+ // Reindex UWP programs
435
+ if ( reindexUwps )
436
+ {
418
437
_ = Task . Run ( IndexUwpProgramsAsync ) ;
419
438
return ;
420
439
}
421
- else
422
- {
423
- _uwpsLock . Release ( ) ;
424
- }
425
440
426
441
await _win32sLock . WaitAsync ( ) ;
427
- if ( _win32s . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) )
442
+ var reindexWin32s = true ;
443
+ try
428
444
{
445
+ reindexWin32s = _win32s . Any ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
429
446
var program = _win32s . First ( x => x . UniqueIdentifier == programToDelete . UniqueIdentifier ) ;
430
447
program . Enabled = false ;
431
448
_settings . DisabledProgramSources . Add ( new ProgramSource ( program ) ) ;
449
+ }
450
+ finally
451
+ {
432
452
_win32sLock . Release ( ) ;
453
+ }
433
454
434
- // Reindex Win32 programs
455
+ // Reindex Win32 programs
456
+ if ( reindexWin32s )
457
+ {
435
458
_ = Task . Run ( IndexWin32ProgramsAsync ) ;
436
459
return ;
437
460
}
438
- else
439
- {
440
- _win32sLock . Release ( ) ;
441
- }
442
461
}
443
462
444
463
public static void StartProcess ( Func < ProcessStartInfo , Process > runProcess , ProcessStartInfo info )
0 commit comments