@@ -1358,138 +1358,138 @@ private async Task QueryResultsAsync(bool searchDelay, bool isReQuery = false, b
1358
1358
1359
1359
try
1360
1360
{
1361
- // Check if the input text matches the query text
1362
- if ( query . Input != QueryText ) return ;
1361
+ // Check if the input text matches the query text
1362
+ if ( query . Input != QueryText ) return ;
1363
1363
1364
- App . API . LogDebug ( ClassName , $ "Start query with ActionKeyword <{ query . ActionKeyword } > and RawQuery <{ query . RawQuery } >") ;
1364
+ App . API . LogDebug ( ClassName , $ "Start query with ActionKeyword <{ query . ActionKeyword } > and RawQuery <{ query . RawQuery } >") ;
1365
1365
1366
- _updateSource ? . Dispose ( ) ;
1366
+ _updateSource ? . Dispose ( ) ;
1367
1367
1368
- var currentUpdateSource = new CancellationTokenSource ( ) ;
1369
- _updateSource = currentUpdateSource ;
1370
- var currentCancellationToken = _updateSource . Token ;
1371
- _updateToken = currentCancellationToken ;
1368
+ var currentUpdateSource = new CancellationTokenSource ( ) ;
1369
+ _updateSource = currentUpdateSource ;
1370
+ var currentCancellationToken = _updateSource . Token ;
1371
+ _updateToken = currentCancellationToken ;
1372
1372
1373
- ProgressBarVisibility = Visibility . Hidden ;
1373
+ ProgressBarVisibility = Visibility . Hidden ;
1374
1374
1375
- _progressQuery = query ;
1376
- _updateQuery = query ;
1375
+ _progressQuery = query ;
1376
+ _updateQuery = query ;
1377
1377
1378
- // Switch to ThreadPool thread
1379
- await TaskScheduler . Default ;
1378
+ // Switch to ThreadPool thread
1379
+ await TaskScheduler . Default ;
1380
1380
1381
- if ( currentCancellationToken . IsCancellationRequested ) return ;
1381
+ if ( currentCancellationToken . IsCancellationRequested ) return ;
1382
1382
1383
- // Update the query's IsReQuery property to true if this is a re-query
1384
- query . IsReQuery = isReQuery ;
1383
+ // Update the query's IsReQuery property to true if this is a re-query
1384
+ query . IsReQuery = isReQuery ;
1385
1385
1386
- ICollection < PluginPair > plugins = Array . Empty < PluginPair > ( ) ;
1387
- if ( currentIsHomeQuery )
1386
+ ICollection < PluginPair > plugins = Array . Empty < PluginPair > ( ) ;
1387
+ if ( currentIsHomeQuery )
1388
+ {
1389
+ if ( Settings . ShowHomePage )
1388
1390
{
1389
- if ( Settings . ShowHomePage )
1390
- {
1391
- plugins = PluginManager . ValidPluginsForHomeQuery ( ) ;
1392
- }
1391
+ plugins = PluginManager . ValidPluginsForHomeQuery ( ) ;
1392
+ }
1393
1393
1394
- PluginIconPath = null ;
1395
- PluginIconSource = null ;
1396
- SearchIconVisibility = Visibility . Visible ;
1394
+ PluginIconPath = null ;
1395
+ PluginIconSource = null ;
1396
+ SearchIconVisibility = Visibility . Visible ;
1397
+ }
1398
+ else
1399
+ {
1400
+ plugins = PluginManager . ValidPluginsForQuery ( query , currentIsDialogJump ) ;
1401
+
1402
+ if ( plugins . Count == 1 )
1403
+ {
1404
+ PluginIconPath = plugins . Single ( ) . Metadata . IcoPath ;
1405
+ PluginIconSource = await App . API . LoadImageAsync ( PluginIconPath ) ;
1406
+ SearchIconVisibility = Visibility . Hidden ;
1397
1407
}
1398
1408
else
1399
1409
{
1400
- plugins = PluginManager . ValidPluginsForQuery ( query , currentIsDialogJump ) ;
1401
-
1402
- if ( plugins . Count == 1 )
1403
- {
1404
- PluginIconPath = plugins . Single ( ) . Metadata . IcoPath ;
1405
- PluginIconSource = await App . API . LoadImageAsync ( PluginIconPath ) ;
1406
- SearchIconVisibility = Visibility . Hidden ;
1407
- }
1408
- else
1409
- {
1410
- PluginIconPath = null ;
1411
- PluginIconSource = null ;
1412
- SearchIconVisibility = Visibility . Visible ;
1413
- }
1410
+ PluginIconPath = null ;
1411
+ PluginIconSource = null ;
1412
+ SearchIconVisibility = Visibility . Visible ;
1414
1413
}
1414
+ }
1415
1415
1416
- App . API . LogDebug ( ClassName , $ "Valid <{ plugins . Count } > plugins: { string . Join ( " " , plugins . Select ( x => $ "<{ x . Metadata . Name } >") ) } ") ;
1416
+ App . API . LogDebug ( ClassName , $ "Valid <{ plugins . Count } > plugins: { string . Join ( " " , plugins . Select ( x => $ "<{ x . Metadata . Name } >") ) } ") ;
1417
1417
1418
- // Do not wait for performance improvement
1419
- /*if (string.IsNullOrEmpty(query.ActionKeyword))
1420
- {
1421
- // Wait 15 millisecond for query change in global query
1422
- // if query changes, return so that it won't be calculated
1423
- await Task.Delay(15, currentCancellationToken);
1424
- if (currentCancellationToken.IsCancellationRequested) return;
1425
- }*/
1418
+ // Do not wait for performance improvement
1419
+ /*if (string.IsNullOrEmpty(query.ActionKeyword))
1420
+ {
1421
+ // Wait 15 millisecond for query change in global query
1422
+ // if query changes, return so that it won't be calculated
1423
+ await Task.Delay(15, currentCancellationToken);
1424
+ if (currentCancellationToken.IsCancellationRequested) return;
1425
+ }*/
1426
1426
1427
- _ = Task . Delay ( 200 , currentCancellationToken ) . ContinueWith ( _ =>
1427
+ _ = Task . Delay ( 200 , currentCancellationToken ) . ContinueWith ( _ =>
1428
+ {
1429
+ // start the progress bar if query takes more than 200 ms and this is the current running query and it didn't finish yet
1430
+ if ( _progressQuery != null && _progressQuery . Input == query . Input )
1428
1431
{
1429
- // start the progress bar if query takes more than 200 ms and this is the current running query and it didn't finish yet
1430
- if ( _progressQuery != null && _progressQuery . Input == query . Input )
1431
- {
1432
- ProgressBarVisibility = Visibility . Visible ;
1433
- }
1434
- } ,
1435
- currentCancellationToken ,
1436
- TaskContinuationOptions . NotOnCanceled ,
1437
- TaskScheduler . Default ) ;
1432
+ ProgressBarVisibility = Visibility . Visible ;
1433
+ }
1434
+ } ,
1435
+ currentCancellationToken ,
1436
+ TaskContinuationOptions . NotOnCanceled ,
1437
+ TaskScheduler . Default ) ;
1438
1438
1439
- // plugins are ICollection, meaning LINQ will get the Count and preallocate Array
1439
+ // plugins are ICollection, meaning LINQ will get the Count and preallocate Array
1440
1440
1441
- Task [ ] tasks ;
1442
- if ( currentIsHomeQuery )
1441
+ Task [ ] tasks ;
1442
+ if ( currentIsHomeQuery )
1443
+ {
1444
+ if ( ShouldClearExistingResultsForNonQuery ( plugins ) )
1443
1445
{
1444
- if ( ShouldClearExistingResultsForNonQuery ( plugins ) )
1445
- {
1446
- // No update tasks and just return
1447
- ClearResults ( ) ;
1448
- return ;
1449
- }
1450
-
1451
- tasks = plugins . Select ( plugin => plugin . Metadata . HomeDisabled switch
1452
- {
1453
- false => QueryTaskAsync ( plugin , currentCancellationToken ) ,
1454
- true => Task . CompletedTask
1455
- } ) . ToArray ( ) ;
1456
-
1457
- // Query history results for home page firstly so it will be put on top of the results
1458
- if ( Settings . ShowHistoryResultsForHomePage )
1459
- {
1460
- QueryHistoryTask ( currentCancellationToken ) ;
1461
- }
1446
+ // No update tasks and just return
1447
+ ClearResults ( ) ;
1448
+ return ;
1462
1449
}
1463
- else
1450
+
1451
+ tasks = plugins . Select ( plugin => plugin . Metadata . HomeDisabled switch
1464
1452
{
1465
- tasks = plugins . Select ( plugin => plugin . Metadata . Disabled switch
1466
- {
1467
- false => QueryTaskAsync ( plugin , currentCancellationToken ) ,
1468
- true => Task . CompletedTask
1469
- } ) . ToArray ( ) ;
1470
- }
1453
+ false => QueryTaskAsync ( plugin , currentCancellationToken ) ,
1454
+ true => Task . CompletedTask
1455
+ } ) . ToArray ( ) ;
1471
1456
1472
- try
1457
+ // Query history results for home page firstly so it will be put on top of the results
1458
+ if ( Settings . ShowHistoryResultsForHomePage )
1473
1459
{
1474
- // Check the code, WhenAll will translate all type of IEnumerable or Collection to Array, so make an array at first
1475
- await Task . WhenAll ( tasks ) ;
1460
+ QueryHistoryTask ( currentCancellationToken ) ;
1476
1461
}
1477
- catch ( OperationCanceledException )
1462
+ }
1463
+ else
1464
+ {
1465
+ tasks = plugins . Select ( plugin => plugin . Metadata . Disabled switch
1478
1466
{
1479
- // nothing to do here
1480
- }
1467
+ false => QueryTaskAsync ( plugin , currentCancellationToken ) ,
1468
+ true => Task . CompletedTask
1469
+ } ) . ToArray ( ) ;
1470
+ }
1481
1471
1482
- if ( currentCancellationToken . IsCancellationRequested ) return ;
1472
+ try
1473
+ {
1474
+ // Check the code, WhenAll will translate all type of IEnumerable or Collection to Array, so make an array at first
1475
+ await Task . WhenAll ( tasks ) ;
1476
+ }
1477
+ catch ( OperationCanceledException )
1478
+ {
1479
+ // nothing to do here
1480
+ }
1483
1481
1484
- // this should happen once after all queries are done so progress bar should continue
1485
- // until the end of all querying
1486
- _progressQuery = null ;
1482
+ if ( currentCancellationToken . IsCancellationRequested ) return ;
1487
1483
1488
- if ( ! currentCancellationToken . IsCancellationRequested )
1489
- {
1490
- // update to hidden if this is still the current query
1491
- ProgressBarVisibility = Visibility . Hidden ;
1492
- }
1484
+ // this should happen once after all queries are done so progress bar should continue
1485
+ // until the end of all querying
1486
+ _progressQuery = null ;
1487
+
1488
+ if ( ! currentCancellationToken . IsCancellationRequested )
1489
+ {
1490
+ // update to hidden if this is still the current query
1491
+ ProgressBarVisibility = Visibility . Hidden ;
1492
+ }
1493
1493
}
1494
1494
finally
1495
1495
{
0 commit comments