@@ -753,8 +753,7 @@ private ResultsViewModel SelectedResults
753753
754754 public Visibility ProgressBarVisibility { get ; set ; }
755755 public Visibility MainWindowVisibility { get ; set ; }
756- public double MainWindowOpacity { get ; set ; } = 1 ;
757-
756+
758757 // This is to be used for determining the visibility status of the mainwindow instead of MainWindowVisibility
759758 // because it is more accurate and reliable representation than using Visibility as a condition check
760759 public bool MainWindowVisibilityStatus { get ; set ; } = true ;
@@ -1454,9 +1453,11 @@ public bool ShouldIgnoreHotkeys()
14541453
14551454 public void Show ( )
14561455 {
1456+ // Invoke on UI thread
14571457 Application . Current . Dispatcher . Invoke ( ( ) =>
14581458 {
1459- if ( Application . Current . MainWindow is MainWindow mainWindow )
1459+ // When application is exitting, the Application.Current will be null
1460+ if ( Application . Current ? . MainWindow is MainWindow mainWindow )
14601461 {
14611462 // 📌 Remove DWM Cloak (Make the window visible normally)
14621463 Win32Helper . DWMSetCloakForWindow ( mainWindow , false ) ;
@@ -1481,10 +1482,10 @@ public void Show()
14811482
14821483 // Update WPF properties
14831484 MainWindowVisibility = Visibility . Visible ;
1484- MainWindowOpacity = 1 ;
14851485 MainWindowVisibilityStatus = true ;
14861486 VisibilityChanged ? . Invoke ( this , new VisibilityChangedEventArgs { IsVisible = true } ) ;
14871487
1488+ // Switch keyboard layout
14881489 if ( StartWithEnglishMode )
14891490 {
14901491 Win32Helper . SwitchToEnglishKeyboardLayout ( true ) ;
@@ -1527,9 +1528,11 @@ public async void Hide()
15271528 break ;
15281529 }
15291530
1531+ // Invoke on UI thread
15301532 Application . Current . Dispatcher . Invoke ( ( ) =>
15311533 {
1532- if ( Application . Current . MainWindow is MainWindow mainWindow )
1534+ // When application is exitting, the Application.Current will be null
1535+ if ( Application . Current ? . MainWindow is MainWindow mainWindow )
15331536 {
15341537 // Set clock and search icon opacity
15351538 var opacity = Settings . UseAnimation ? 0.0 : 1.0 ;
@@ -1549,6 +1552,7 @@ public async void Hide()
15491552 }
15501553 } , DispatcherPriority . Render ) ;
15511554
1555+ // Switch keyboard layout
15521556 if ( StartWithEnglishMode )
15531557 {
15541558 Win32Helper . RestorePreviousKeyboardLayout ( ) ;
@@ -1558,7 +1562,6 @@ public async void Hide()
15581562 await Task . Delay ( 50 ) ;
15591563
15601564 // Update WPF properties
1561- //MainWindowOpacity = 0;
15621565 MainWindowVisibilityStatus = false ;
15631566 MainWindowVisibility = Visibility . Collapsed ;
15641567 VisibilityChanged ? . Invoke ( this , new VisibilityChangedEventArgs { IsVisible = false } ) ;
0 commit comments