22
22
using Flow . Launcher . Infrastructure . UserSettings ;
23
23
using Flow . Launcher . Plugin . SharedCommands ;
24
24
using Flow . Launcher . ViewModel ;
25
+ using Microsoft . Win32 ;
25
26
using ModernWpf . Controls ;
26
27
using DataObject = System . Windows . DataObject ;
27
28
using Key = System . Windows . Input . Key ;
@@ -88,6 +89,8 @@ public MainWindow()
88
89
89
90
InitSoundEffects ( ) ;
90
91
DataObject . AddPastingHandler ( QueryTextBox , QueryTextBox_OnPaste ) ;
92
+
93
+ SystemEvents . PowerModeChanged += SystemEvents_PowerModeChanged ;
91
94
}
92
95
93
96
#endregion
@@ -540,16 +543,29 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
540
543
541
544
#region Window Sound Effects
542
545
546
+ private void SystemEvents_PowerModeChanged ( object sender , PowerModeChangedEventArgs e )
547
+ {
548
+ // Fix for sound not playing after sleep / hibernate
549
+ // https://stackoverflow.com/questions/64805186/mediaplayer-doesnt-play-after-computer-sleeps
550
+ if ( e . Mode == PowerModes . Resume )
551
+ {
552
+ InitSoundEffects ( ) ;
553
+ }
554
+ }
555
+
543
556
private void InitSoundEffects ( )
544
557
{
545
558
if ( _settings . WMPInstalled )
546
559
{
560
+ animationSoundWMP ? . Close ( ) ;
547
561
animationSoundWMP = new MediaPlayer ( ) ;
548
562
animationSoundWMP . Open ( new Uri ( AppContext . BaseDirectory + "Resources\\ open.wav" ) ) ;
549
563
}
550
564
else
551
565
{
566
+ animationSoundWPF ? . Dispose ( ) ;
552
567
animationSoundWPF = new SoundPlayer ( AppContext . BaseDirectory + "Resources\\ open.wav" ) ;
568
+ animationSoundWPF . Load ( ) ;
553
569
}
554
570
}
555
571
@@ -816,7 +832,7 @@ private void InitProgressbarAnimation()
816
832
{
817
833
Name = progressBarAnimationName , Storyboard = progressBarStoryBoard
818
834
} ;
819
-
835
+
820
836
var stopStoryboard = new StopStoryboard ( )
821
837
{
822
838
BeginStoryboardName = progressBarAnimationName
@@ -837,7 +853,7 @@ private void InitProgressbarAnimation()
837
853
progressStyle . Triggers . Add ( trigger ) ;
838
854
839
855
ProgressBar . Style = progressStyle ;
840
-
856
+
841
857
_viewModel . ProgressBarVisibility = Visibility . Hidden ;
842
858
}
843
859
@@ -885,7 +901,7 @@ private void WindowAnimation()
885
901
Duration = TimeSpan . FromMilliseconds ( animationLength ) ,
886
902
FillBehavior = FillBehavior . HoldEnd
887
903
} ;
888
-
904
+
889
905
var rightMargin = GetThicknessFromStyle ( ClockPanel . Style , new Thickness ( 0 , 0 , DefaultRightMargin , 0 ) ) . Right ;
890
906
891
907
var thicknessAnimation = new ThicknessAnimation
@@ -913,10 +929,10 @@ private void WindowAnimation()
913
929
clocksb . Children . Add ( ClockOpacity ) ;
914
930
iconsb . Children . Add ( IconMotion ) ;
915
931
iconsb . Children . Add ( IconOpacity ) ;
916
-
932
+
917
933
_settings . WindowLeft = Left ;
918
934
_isArrowKeyPressed = false ;
919
-
935
+
920
936
clocksb . Begin ( ClockPanel ) ;
921
937
iconsb . Begin ( SearchIcon ) ;
922
938
}
@@ -1088,7 +1104,7 @@ private void QueryTextBox_OnPreviewDragOver(object sender, DragEventArgs e)
1088
1104
{
1089
1105
e . Handled = true ;
1090
1106
}
1091
-
1107
+
1092
1108
#endregion
1093
1109
1094
1110
#region Placeholder
@@ -1140,7 +1156,7 @@ private void SetupResizeMode()
1140
1156
}
1141
1157
1142
1158
#endregion
1143
-
1159
+
1144
1160
#region Search Delay
1145
1161
1146
1162
private void QueryTextBox_TextChanged1 ( object sender , TextChangedEventArgs e )
@@ -1162,6 +1178,9 @@ protected virtual void Dispose(bool disposing)
1162
1178
{
1163
1179
_hwndSource ? . Dispose ( ) ;
1164
1180
_notifyIcon ? . Dispose ( ) ;
1181
+ animationSoundWMP ? . Close ( ) ;
1182
+ animationSoundWPF ? . Dispose ( ) ;
1183
+ SystemEvents . PowerModeChanged -= SystemEvents_PowerModeChanged ;
1165
1184
}
1166
1185
1167
1186
_disposed = true ;
0 commit comments