@@ -101,11 +101,16 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
101
101
// Check first launch
102
102
if ( _settings . FirstLaunch )
103
103
{
104
+ // Set First Launch to false
104
105
_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
105
111
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
109
114
var WelcomeWindow = new WelcomeWindow ( ) ;
110
115
WelcomeWindow . Show ( ) ;
111
116
}
@@ -161,24 +166,68 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
161
166
{
162
167
if ( _viewModel . MainWindowVisibilityStatus )
163
168
{
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
164
186
if ( _settings . UseSound )
165
187
{
166
188
SoundPlay ( ) ;
167
189
}
168
190
191
+ // Update position & Activate
169
192
UpdatePosition ( ) ;
170
- _viewModel . ResetPreview ( ) ;
171
193
Activate ( ) ;
172
- QueryTextBox . Focus ( ) ;
173
- _settings . ActivateTimes ++ ;
194
+
195
+ // Reset preview
196
+ _viewModel . ResetPreview ( ) ;
197
+
198
+ // Select last query if need
174
199
if ( ! _viewModel . LastQuerySelected )
175
200
{
176
201
QueryTextBox . SelectAll ( ) ;
177
202
_viewModel . LastQuerySelected = true ;
178
203
}
179
204
205
+ // Focus query box
206
+ QueryTextBox . Focus ( ) ;
207
+
208
+ // Play window animation
180
209
if ( _settings . UseAnimation )
210
+ {
181
211
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 ( ) ;
182
231
}
183
232
} ) ;
184
233
break ;
@@ -191,7 +240,6 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
191
240
Dispatcher . Invoke ( ( ) => QueryTextBox . CaretIndex = QueryTextBox . Text . Length ) ;
192
241
_viewModel . QueryTextCursorMovedToEnd = false ;
193
242
}
194
-
195
243
break ;
196
244
case nameof ( MainViewModel . GameModeStatus ) :
197
245
_notifyIcon . Icon = _viewModel . GameModeStatus
@@ -248,7 +296,8 @@ private async void OnClosing(object sender, CancelEventArgs e)
248
296
Notification . Uninstall ( ) ;
249
297
// After plugins are all disposed, we can close the main window
250
298
_canClose = true ;
251
- Close ( ) ;
299
+ // Use this instead of Close() to avoid InvalidOperationException when calling Close() in OnClosing event
300
+ Application . Current . Shutdown ( ) ;
252
301
}
253
302
}
254
303
@@ -280,8 +329,8 @@ private async void OnDeactivated(object sender, EventArgs e)
280
329
_settings . WindowLeft = Left ;
281
330
_settings . WindowTop = Top ;
282
331
283
- ClockPanel . Opacity = 0 ;
284
- SearchIcon . Opacity = 0 ;
332
+ ClockPanel . Opacity = 0.0 ;
333
+ SearchIcon . Opacity = 0.0 ;
285
334
286
335
// This condition stops extra hide call when animator is on,
287
336
// which causes the toggling to occasional hide instead of show.
@@ -291,7 +340,9 @@ private async void OnDeactivated(object sender, EventArgs e)
291
340
// This also stops the mainwindow from flickering occasionally after Settings window is opened
292
341
// and always after Settings window is closed.
293
342
if ( _settings . UseAnimation )
343
+ {
294
344
await Task . Delay ( 100 ) ;
345
+ }
295
346
296
347
if ( _settings . HideWhenDeactivated && ! _viewModel . ExternalPreviewVisible )
297
348
{
@@ -765,12 +816,6 @@ private void WindowAnimation()
765
816
{
766
817
_isArrowKeyPressed = true ;
767
818
768
- UpdatePosition ( ) ;
769
-
770
- var opacity = _settings . UseAnimation ? 0.0 : 1.0 ;
771
- ClockPanel . Opacity = opacity ;
772
- SearchIcon . Opacity = opacity ;
773
-
774
819
var clocksb = new Storyboard ( ) ;
775
820
var iconsb = new Storyboard ( ) ;
776
821
var easing = new CircleEase { EasingMode = EasingMode . EaseInOut } ;
@@ -904,6 +949,7 @@ private void UpdateClockPanelVisibility()
904
949
905
950
ClockPanel . BeginAnimation ( OpacityProperty , fadeOut ) ;
906
951
}
952
+
907
953
// ✅ 4. When showing ClockPanel (apply fade-in animation)
908
954
else if ( shouldShowClock && ClockPanel . Visibility != Visibility . Visible && ! _isClockPanelAnimating )
909
955
{
@@ -927,7 +973,6 @@ private void UpdateClockPanelVisibility()
927
973
}
928
974
}
929
975
930
-
931
976
private static double GetOpacityFromStyle ( Style style , double defaultOpacity = 1.0 )
932
977
{
933
978
if ( style == null )
0 commit comments