@@ -39,11 +39,13 @@ public partial class MainWindow : IDisposable
39
39
private NotifyIcon _notifyIcon ;
40
40
41
41
// Window Context Menu
42
- private readonly ContextMenu contextMenu = new ( ) ;
42
+ private readonly ContextMenu _contextMenu = new ( ) ;
43
43
private readonly MainViewModel _viewModel ;
44
44
45
+ // Window Event: Close Event
46
+ private bool _canClose = false ;
45
47
// Window Event: Key Event
46
- private bool isArrowKeyPressed = false ;
48
+ private bool _isArrowKeyPressed = false ;
47
49
48
50
// Window Sound Effects
49
51
private MediaPlayer animationSoundWMP ;
@@ -60,7 +62,7 @@ public partial class MainWindow : IDisposable
60
62
private bool _isClockPanelAnimating = false ;
61
63
62
64
// IDisposable
63
- private bool _disposedValue = false ;
65
+ private bool _disposed = false ;
64
66
65
67
#endregion
66
68
@@ -231,10 +233,18 @@ private async void OnLoaded(object sender, RoutedEventArgs _)
231
233
. AddValueChanged ( History , ( s , e ) => UpdateClockPanelVisibility ( ) ) ;
232
234
}
233
235
234
- private void OnClosing ( object sender , CancelEventArgs e )
236
+ private async void OnClosing ( object sender , CancelEventArgs e )
235
237
{
236
- _notifyIcon . Visible = false ;
237
- Notification . Uninstall ( ) ;
238
+ if ( ! _canClose )
239
+ {
240
+ _notifyIcon . Visible = false ;
241
+ App . API . SaveAppAllSettings ( ) ;
242
+ e . Cancel = true ;
243
+ await PluginManager . DisposePluginsAsync ( ) ;
244
+ Notification . Uninstall ( ) ;
245
+ _canClose = true ;
246
+ Close ( ) ;
247
+ }
238
248
}
239
249
240
250
private void OnClosed ( object sender , EventArgs e )
@@ -292,12 +302,12 @@ private void OnKeyDown(object sender, KeyEventArgs e)
292
302
switch ( e . Key )
293
303
{
294
304
case Key . Down :
295
- isArrowKeyPressed = true ;
305
+ _isArrowKeyPressed = true ;
296
306
_viewModel . SelectNextItemCommand . Execute ( null ) ;
297
307
e . Handled = true ;
298
308
break ;
299
309
case Key . Up :
300
- isArrowKeyPressed = true ;
310
+ _isArrowKeyPressed = true ;
301
311
_viewModel . SelectPrevItemCommand . Execute ( null ) ;
302
312
e . Handled = true ;
303
313
break ;
@@ -355,13 +365,13 @@ private void OnKeyUp(object sender, KeyEventArgs e)
355
365
{
356
366
if ( e . Key == Key . Up || e . Key == Key . Down )
357
367
{
358
- isArrowKeyPressed = false ;
368
+ _isArrowKeyPressed = false ;
359
369
}
360
370
}
361
371
362
372
private void OnPreviewMouseMove ( object sender , MouseEventArgs e )
363
373
{
364
- if ( isArrowKeyPressed )
374
+ if ( _isArrowKeyPressed )
365
375
{
366
376
e . Handled = true ; // Ignore Mouse Hover when press Arrowkeys
367
377
}
@@ -531,11 +541,11 @@ private void InitializeNotifyIcon()
531
541
gamemode . ToolTip = App . API . GetTranslation ( "GameModeToolTip" ) ;
532
542
positionreset . ToolTip = App . API . GetTranslation ( "PositionResetToolTip" ) ;
533
543
534
- contextMenu . Items . Add ( open ) ;
535
- contextMenu . Items . Add ( gamemode ) ;
536
- contextMenu . Items . Add ( positionreset ) ;
537
- contextMenu . Items . Add ( settings ) ;
538
- contextMenu . Items . Add ( exit ) ;
544
+ _contextMenu . Items . Add ( open ) ;
545
+ _contextMenu . Items . Add ( gamemode ) ;
546
+ _contextMenu . Items . Add ( positionreset ) ;
547
+ _contextMenu . Items . Add ( settings ) ;
548
+ _contextMenu . Items . Add ( exit ) ;
539
549
540
550
_notifyIcon . MouseClick += ( o , e ) =>
541
551
{
@@ -546,22 +556,22 @@ private void InitializeNotifyIcon()
546
556
break ;
547
557
case MouseButtons . Right :
548
558
549
- contextMenu . IsOpen = true ;
559
+ _contextMenu . IsOpen = true ;
550
560
// Get context menu handle and bring it to the foreground
551
- if ( PresentationSource . FromVisual ( contextMenu ) is HwndSource hwndSource )
561
+ if ( PresentationSource . FromVisual ( _contextMenu ) is HwndSource hwndSource )
552
562
{
553
563
Win32Helper . SetForegroundWindow ( hwndSource . Handle ) ;
554
564
}
555
565
556
- contextMenu . Focus ( ) ;
566
+ _contextMenu . Focus ( ) ;
557
567
break ;
558
568
}
559
569
} ;
560
570
}
561
571
562
572
private void UpdateNotifyIconText ( )
563
573
{
564
- var menu = contextMenu ;
574
+ var menu = _contextMenu ;
565
575
( ( MenuItem ) menu . Items [ 0 ] ) . Header = App . API . GetTranslation ( "iconTrayOpen" ) +
566
576
" (" + _settings . Hotkey + ")" ;
567
577
( ( MenuItem ) menu . Items [ 1 ] ) . Header = App . API . GetTranslation ( "GameMode" ) ;
@@ -757,7 +767,7 @@ private void WindowAnimation()
757
767
if ( _animating )
758
768
return ;
759
769
760
- isArrowKeyPressed = true ;
770
+ _isArrowKeyPressed = true ;
761
771
_animating = true ;
762
772
UpdatePosition ( false ) ;
763
773
@@ -835,7 +845,7 @@ private void WindowAnimation()
835
845
836
846
clocksb . Completed += ( _ , _ ) => _animating = false ;
837
847
_settings . WindowLeft = Left ;
838
- isArrowKeyPressed = false ;
848
+ _isArrowKeyPressed = false ;
839
849
840
850
if ( QueryTextBox . Text . Length == 0 )
841
851
{
@@ -1009,14 +1019,15 @@ private void QueryTextBox_OnPreviewDragOver(object sender, DragEventArgs e)
1009
1019
1010
1020
protected virtual void Dispose ( bool disposing )
1011
1021
{
1012
- if ( ! _disposedValue )
1022
+ if ( ! _disposed )
1013
1023
{
1014
1024
if ( disposing )
1015
1025
{
1016
1026
_hwndSource ? . Dispose ( ) ;
1027
+ _notifyIcon ? . Dispose ( ) ;
1017
1028
}
1018
1029
1019
- _disposedValue = true ;
1030
+ _disposed = true ;
1020
1031
}
1021
1032
}
1022
1033
0 commit comments