@@ -101,11 +101,16 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
101101 // Check first launch
102102 if ( _settings . FirstLaunch )
103103 {
104+ // Set First Launch to false
104105 _settings . FirstLaunch = false ;
106+
107+ // Set Backdrop Type to Acrylic for Windows 11 when First Launch. Default is None
108+ if ( Win32Helper . IsBackdropSupported ( ) ) _settings . BackdropType = BackdropTypes . Acrylic ;
109+
110+ // Save settings
105111 App . API . SaveAppAllSettings ( ) ;
106- /* Set Backdrop Type to Acrylic for Windows 11 when First Launch. Default is None. */
107- if ( OperatingSystem . IsWindowsVersionAtLeast ( 10 , 0 , 22000 ) )
108- _settings . BackdropType = BackdropTypes . Acrylic ;
112+
113+ // Show Welcome Window
109114 var WelcomeWindow = new WelcomeWindow ( ) ;
110115 WelcomeWindow . Show ( ) ;
111116 }
@@ -161,24 +166,68 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
161166 {
162167 if ( _viewModel . MainWindowVisibilityStatus )
163168 {
169+ // Set clock and search icon opacity
170+ var opacity = _settings . UseAnimation ? 0.0 : 1.0 ;
171+ ClockPanel . Opacity = opacity ;
172+ SearchIcon . Opacity = opacity ;
173+
174+ // Set clock and search icon visibility
175+ ClockPanel . Visibility = string . IsNullOrEmpty ( _viewModel . QueryText ) ? Visibility . Visible : Visibility . Collapsed ;
176+ if ( _viewModel . PluginIconSource != null )
177+ {
178+ SearchIcon . Opacity = 0.0 ;
179+ }
180+ else
181+ {
182+ _viewModel . SearchIconVisibility = Visibility . Visible ;
183+ }
184+
185+ // Play sound effect before activing the window
164186 if ( _settings . UseSound )
165187 {
166188 SoundPlay ( ) ;
167189 }
168190
191+ // Update position & Activate
169192 UpdatePosition ( ) ;
170- _viewModel . ResetPreview ( ) ;
171193 Activate ( ) ;
172- QueryTextBox . Focus ( ) ;
173- _settings . ActivateTimes ++ ;
194+
195+ // Reset preview
196+ _viewModel . ResetPreview ( ) ;
197+
198+ // Select last query if need
174199 if ( ! _viewModel . LastQuerySelected )
175200 {
176201 QueryTextBox . SelectAll ( ) ;
177202 _viewModel . LastQuerySelected = true ;
178203 }
179204
205+ // Focus query box
206+ QueryTextBox . Focus ( ) ;
207+
208+ // Play window animation
180209 if ( _settings . UseAnimation )
210+ {
181211 WindowAnimation ( ) ;
212+ }
213+
214+ // Update activate times
215+ _settings . ActivateTimes ++ ;
216+ }
217+ else
218+ {
219+ // Set clock and search icon opacity
220+ var opacity = _settings . UseAnimation ? 0.0 : 1.0 ;
221+ ClockPanel . Opacity = opacity ;
222+ SearchIcon . Opacity = opacity ;
223+
224+ // Set clock and search icon visibility
225+ ClockPanel . Visibility = Visibility . Hidden ;
226+ _viewModel . SearchIconVisibility = Visibility . Hidden ;
227+
228+ // Force UI update
229+ ClockPanel . UpdateLayout ( ) ;
230+ SearchIcon . UpdateLayout ( ) ;
182231 }
183232 } ) ;
184233 break ;
@@ -191,7 +240,6 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
191240 Dispatcher . Invoke ( ( ) => QueryTextBox . CaretIndex = QueryTextBox . Text . Length ) ;
192241 _viewModel . QueryTextCursorMovedToEnd = false ;
193242 }
194-
195243 break ;
196244 case nameof ( MainViewModel . GameModeStatus ) :
197245 _notifyIcon . Icon = _viewModel . GameModeStatus
@@ -248,7 +296,8 @@ private async void OnClosing(object sender, CancelEventArgs e)
248296 Notification . Uninstall ( ) ;
249297 // After plugins are all disposed, we can close the main window
250298 _canClose = true ;
251- Close ( ) ;
299+ // Use this instead of Close() to avoid InvalidOperationException when calling Close() in OnClosing event
300+ Application . Current . Shutdown ( ) ;
252301 }
253302 }
254303
@@ -280,8 +329,8 @@ private async void OnDeactivated(object sender, EventArgs e)
280329 _settings . WindowLeft = Left ;
281330 _settings . WindowTop = Top ;
282331
283- ClockPanel . Opacity = 0 ;
284- SearchIcon . Opacity = 0 ;
332+ ClockPanel . Opacity = 0.0 ;
333+ SearchIcon . Opacity = 0.0 ;
285334
286335 // This condition stops extra hide call when animator is on,
287336 // which causes the toggling to occasional hide instead of show.
@@ -291,7 +340,9 @@ private async void OnDeactivated(object sender, EventArgs e)
291340 // This also stops the mainwindow from flickering occasionally after Settings window is opened
292341 // and always after Settings window is closed.
293342 if ( _settings . UseAnimation )
343+ {
294344 await Task . Delay ( 100 ) ;
345+ }
295346
296347 if ( _settings . HideWhenDeactivated && ! _viewModel . ExternalPreviewVisible )
297348 {
@@ -765,12 +816,6 @@ private void WindowAnimation()
765816 {
766817 _isArrowKeyPressed = true ;
767818
768- UpdatePosition ( ) ;
769-
770- var opacity = _settings . UseAnimation ? 0.0 : 1.0 ;
771- ClockPanel . Opacity = opacity ;
772- SearchIcon . Opacity = opacity ;
773-
774819 var clocksb = new Storyboard ( ) ;
775820 var iconsb = new Storyboard ( ) ;
776821 var easing = new CircleEase { EasingMode = EasingMode . EaseInOut } ;
@@ -904,6 +949,7 @@ private void UpdateClockPanelVisibility()
904949
905950 ClockPanel . BeginAnimation ( OpacityProperty , fadeOut ) ;
906951 }
952+
907953 // ✅ 4. When showing ClockPanel (apply fade-in animation)
908954 else if ( shouldShowClock && ClockPanel . Visibility != Visibility . Visible && ! _isClockPanelAnimating )
909955 {
@@ -927,7 +973,6 @@ private void UpdateClockPanelVisibility()
927973 }
928974 }
929975
930-
931976 private static double GetOpacityFromStyle ( Style style , double defaultOpacity = 1.0 )
932977 {
933978 if ( style == null )
0 commit comments