1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . ComponentModel ;
4
- using System . Diagnostics ;
5
4
using System . Globalization ;
6
- using System . Windows . Input ;
7
5
using System . Linq ;
8
6
using System . Text ;
9
7
using System . Threading ;
10
8
using System . Threading . Channels ;
11
9
using System . Threading . Tasks ;
12
10
using System . Windows ;
11
+ using System . Windows . Input ;
13
12
using System . Windows . Media ;
14
13
using System . Windows . Threading ;
15
14
using CommunityToolkit . Mvvm . DependencyInjection ;
@@ -631,7 +630,15 @@ private void DecreaseMaxResult()
631
630
/// <param name="isReQuery">Force query even when Query Text doesn't change</param>
632
631
public void ChangeQueryText ( string queryText , bool isReQuery = false )
633
632
{
634
- Application . Current . Dispatcher . Invoke ( ( ) =>
633
+ _ = ChangeQueryTextAsync ( queryText , isReQuery ) ;
634
+ }
635
+
636
+ /// <summary>
637
+ /// Async version of <see cref="ChangeQueryText"/>
638
+ /// </summary>
639
+ private async Task ChangeQueryTextAsync ( string queryText , bool isReQuery = false )
640
+ {
641
+ await Application . Current . Dispatcher . InvokeAsync ( async ( ) =>
635
642
{
636
643
BackToQueryResults ( ) ;
637
644
@@ -645,7 +652,7 @@ public void ChangeQueryText(string queryText, bool isReQuery = false)
645
652
}
646
653
else if ( isReQuery )
647
654
{
648
- Query ( isReQuery : true ) ;
655
+ await QueryAsync ( isReQuery : true ) ;
649
656
}
650
657
651
658
QueryTextCursorMovedToEnd = true ;
@@ -1017,10 +1024,15 @@ private bool QueryResultsPreviewed()
1017
1024
#region Query
1018
1025
1019
1026
private void Query ( bool isReQuery = false )
1027
+ {
1028
+ _ = QueryAsync ( isReQuery ) ;
1029
+ }
1030
+
1031
+ private async Task QueryAsync ( bool isReQuery = false )
1020
1032
{
1021
1033
if ( QueryResultsSelected ( ) )
1022
1034
{
1023
- _ = QueryResultsAsync ( isReQuery ) ;
1035
+ await QueryResultsAsync ( isReQuery ) ;
1024
1036
}
1025
1037
else if ( ContextMenuSelected ( ) )
1026
1038
{
@@ -1054,10 +1066,10 @@ private void QueryContextMenu()
1054
1066
(
1055
1067
r =>
1056
1068
{
1057
- var match = StringMatcher . FuzzySearch ( query , r . Title ) ;
1069
+ var match = App . API . FuzzySearch ( query , r . Title ) ;
1058
1070
if ( ! match . IsSearchPrecisionScoreMet ( ) )
1059
1071
{
1060
- match = StringMatcher . FuzzySearch ( query , r . SubTitle ) ;
1072
+ match = App . API . FuzzySearch ( query , r . SubTitle ) ;
1061
1073
}
1062
1074
1063
1075
if ( ! match . IsSearchPrecisionScoreMet ( ) ) return false ;
@@ -1099,7 +1111,7 @@ private void QueryHistory()
1099
1111
Action = _ =>
1100
1112
{
1101
1113
SelectedResults = Results ;
1102
- ChangeQueryText ( h . Query ) ;
1114
+ App . API . ChangeQuery ( h . Query ) ;
1103
1115
return false ;
1104
1116
}
1105
1117
} ;
@@ -1110,8 +1122,8 @@ private void QueryHistory()
1110
1122
{
1111
1123
var filtered = results . Where
1112
1124
(
1113
- r => StringMatcher . FuzzySearch ( query , r . Title ) . IsSearchPrecisionScoreMet ( ) ||
1114
- StringMatcher . FuzzySearch ( query , r . SubTitle ) . IsSearchPrecisionScoreMet ( )
1125
+ r => App . API . FuzzySearch ( query , r . Title ) . IsSearchPrecisionScoreMet ( ) ||
1126
+ App . API . FuzzySearch ( query , r . SubTitle ) . IsSearchPrecisionScoreMet ( )
1115
1127
) . ToList ( ) ;
1116
1128
History . AddResults ( filtered , id ) ;
1117
1129
}
@@ -1430,35 +1442,31 @@ public bool ShouldIgnoreHotkeys()
1430
1442
1431
1443
#region Public Methods
1432
1444
1433
- public void Show ( )
1445
+ #pragma warning disable VSTHRD100 // Avoid async void methods
1446
+
1447
+ public async void Show ( )
1434
1448
{
1435
- Application . Current . Dispatcher . Invoke ( ( ) =>
1449
+ await Application . Current . Dispatcher . InvokeAsync ( ( ) =>
1436
1450
{
1437
1451
if ( Application . Current . MainWindow is MainWindow mainWindow )
1438
1452
{
1439
1453
// 📌 Remove DWM Cloak (Make the window visible normally)
1440
1454
Win32Helper . DWMSetCloakForWindow ( mainWindow , false ) ;
1441
-
1442
- //Clock and SearchIcon hide when show situation
1443
- if ( Settings . UseAnimation )
1444
- {
1445
- mainWindow . ClockPanel . Opacity = 0 ;
1446
- mainWindow . SearchIcon . Opacity = 0 ;
1447
- }
1448
- else
1449
- {
1450
- mainWindow . ClockPanel . Opacity = 1 ;
1451
- mainWindow . SearchIcon . Opacity = 1 ;
1452
- }
1453
1455
1454
- if ( mainWindow . QueryTextBox . Text . Length != 0 )
1456
+ // Clock and SearchIcon hide when show situation
1457
+ var opacity = Settings . UseAnimation ? 0.0 : 1.0 ;
1458
+ mainWindow . ClockPanel . Opacity = opacity ;
1459
+ mainWindow . SearchIcon . Opacity = opacity ;
1460
+
1461
+ if ( QueryText . Length != 0 )
1455
1462
{
1456
1463
mainWindow . ClockPanel . Visibility = Visibility . Collapsed ;
1457
1464
}
1458
1465
else
1459
1466
{
1460
1467
mainWindow . ClockPanel . Visibility = Visibility . Visible ;
1461
1468
}
1469
+
1462
1470
if ( PluginIconSource != null )
1463
1471
{
1464
1472
mainWindow . SearchIcon . Opacity = 0 ;
@@ -1467,30 +1475,28 @@ public void Show()
1467
1475
{
1468
1476
SearchIconVisibility = Visibility . Visible ;
1469
1477
}
1478
+
1470
1479
// 📌 Restore UI elements
1471
1480
//mainWindow.SearchIcon.Visibility = Visibility.Visible;
1472
1481
if ( Settings . UseAnimation )
1473
1482
{
1474
- Application . Current . Dispatcher . BeginInvoke ( ( ) =>
1475
- mainWindow . WindowAnimation ( ) ) ;
1483
+ mainWindow . WindowAnimation ( ) ;
1476
1484
}
1477
1485
}
1486
+ } , DispatcherPriority . Render ) ;
1478
1487
1479
- // Update WPF properties
1480
- MainWindowVisibility = Visibility . Visible ;
1481
- MainWindowOpacity = 1 ;
1482
- MainWindowVisibilityStatus = true ;
1483
- VisibilityChanged ? . Invoke ( this , new VisibilityChangedEventArgs { IsVisible = true } ) ;
1488
+ // Update WPF properties
1489
+ MainWindowVisibility = Visibility . Visible ;
1490
+ MainWindowOpacity = 1 ;
1491
+ MainWindowVisibilityStatus = true ;
1492
+ VisibilityChanged ? . Invoke ( this , new VisibilityChangedEventArgs { IsVisible = true } ) ;
1484
1493
1485
- if ( StartWithEnglishMode )
1486
- {
1487
- Win32Helper . SwitchToEnglishKeyboardLayout ( true ) ;
1488
- }
1489
- } ) ;
1494
+ if ( StartWithEnglishMode )
1495
+ {
1496
+ Win32Helper . SwitchToEnglishKeyboardLayout ( true ) ;
1497
+ }
1490
1498
}
1491
1499
1492
- #pragma warning disable VSTHRD100 // Avoid async void methods
1493
-
1494
1500
public async void Hide ( )
1495
1501
{
1496
1502
lastHistoryIndex = 1 ;
@@ -1505,59 +1511,47 @@ public async void Hide()
1505
1511
SelectedResults = Results ;
1506
1512
}
1507
1513
1508
- // 📌 Immediately apply text reset + force UI update
1509
- /*if (Settings.LastQueryMode == LastQueryMode.Empty)
1510
- {
1511
- ChangeQueryText(string.Empty);
1512
- await Task.Delay(1); // Wait for one frame to ensure UI reflects changes
1513
- Application.Current.Dispatcher.Invoke(Application.Current.MainWindow.UpdateLayout); // Force UI update
1514
- }*/
1515
-
1516
1514
switch ( Settings . LastQueryMode )
1517
1515
{
1518
1516
case LastQueryMode . Empty :
1519
- ChangeQueryText ( string . Empty ) ;
1520
- await Task . Delay ( 1 ) ;
1517
+ await ChangeQueryTextAsync ( string . Empty ) ;
1521
1518
break ;
1522
1519
case LastQueryMode . Preserved :
1523
1520
case LastQueryMode . Selected :
1524
- LastQuerySelected = ( Settings . LastQueryMode == LastQueryMode . Preserved ) ;
1521
+ LastQuerySelected = Settings . LastQueryMode == LastQueryMode . Preserved ;
1525
1522
break ;
1526
-
1527
1523
case LastQueryMode . ActionKeywordPreserved :
1528
1524
case LastQueryMode . ActionKeywordSelected :
1529
1525
var newQuery = _lastQuery . ActionKeyword ;
1526
+
1530
1527
if ( ! string . IsNullOrEmpty ( newQuery ) )
1531
1528
newQuery += " " ;
1532
- ChangeQueryText ( newQuery ) ;
1529
+ await ChangeQueryTextAsync ( newQuery ) ;
1533
1530
1534
1531
if ( Settings . LastQueryMode == LastQueryMode . ActionKeywordSelected )
1535
1532
LastQuerySelected = false ;
1536
1533
break ;
1537
1534
}
1538
1535
1539
- if ( Application . Current . MainWindow is MainWindow mainWindow )
1536
+ await Application . Current . Dispatcher . InvokeAsync ( ( ) =>
1540
1537
{
1541
- // 📌 Set Opacity of icon and clock to 0 and apply Visibility.Hidden
1542
- if ( Settings . UseAnimation )
1543
- {
1544
- mainWindow . ClockPanel . Opacity = 0 ;
1545
- mainWindow . SearchIcon . Opacity = 0 ;
1546
- }
1547
- else
1538
+ if ( Application . Current . MainWindow is MainWindow mainWindow )
1548
1539
{
1549
- mainWindow . ClockPanel . Opacity = 1 ;
1550
- mainWindow . SearchIcon . Opacity = 1 ;
1540
+ // 📌 Set Opacity of icon and clock to 0 and apply Visibility.Hidden
1541
+ var opacity = Settings . UseAnimation ? 0.0 : 1.0 ;
1542
+ mainWindow . ClockPanel . Opacity = opacity ;
1543
+ mainWindow . SearchIcon . Opacity = opacity ;
1544
+ mainWindow . ClockPanel . Visibility = Visibility . Hidden ;
1545
+ SearchIconVisibility = Visibility . Hidden ;
1546
+
1547
+ // Force UI update
1548
+ mainWindow . ClockPanel . UpdateLayout ( ) ;
1549
+ mainWindow . SearchIcon . UpdateLayout ( ) ;
1550
+
1551
+ // 📌 Apply DWM Cloak (Completely hide the window)
1552
+ Win32Helper . DWMSetCloakForWindow ( mainWindow , true ) ;
1551
1553
}
1552
- mainWindow . ClockPanel . Visibility = Visibility . Hidden ;
1553
- SearchIconVisibility = Visibility . Hidden ;
1554
-
1555
- // Force UI update
1556
- mainWindow . ClockPanel . UpdateLayout ( ) ;
1557
- mainWindow . SearchIcon . UpdateLayout ( ) ;
1558
- // 📌 Apply DWM Cloak (Completely hide the window)
1559
- Win32Helper . DWMSetCloakForWindow ( mainWindow , true ) ;
1560
- }
1554
+ } ) ;
1561
1555
1562
1556
if ( StartWithEnglishMode )
1563
1557
{
0 commit comments