2525using Flow . Launcher . Plugin . SharedCommands ;
2626using Flow . Launcher . Plugin . SharedModels ;
2727using Flow . Launcher . ViewModel ;
28- using Microsoft . Win32 ;
2928using ModernWpf . Controls ;
3029using DataObject = System . Windows . DataObject ;
3130using Key = System . Windows . Input . Key ;
@@ -96,7 +95,6 @@ public MainWindow()
9695
9796 InitSoundEffects ( ) ;
9897 DataObject . AddPastingHandler ( QueryTextBox , QueryTextBox_OnPaste ) ;
99- SystemEvents . PowerModeChanged += SystemEvents_PowerModeChanged ;
10098 _viewModel . ActualApplicationThemeChanged += ViewModel_ActualApplicationThemeChanged ;
10199 }
102100
@@ -670,6 +668,16 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
670668 handled = true ;
671669 }
672670 break ;
671+ case Win32Helper . WM_POWERBROADCAST : // Handle power broadcast messages
672+ // https://learn.microsoft.com/en-us/windows/win32/power/wm-powerbroadcast
673+ if ( wParam . ToInt32 ( ) == Win32Helper . PBT_APMRESUMEAUTOMATIC )
674+ {
675+ // Fix for sound not playing after sleep / hibernate
676+ // https://stackoverflow.com/questions/64805186/mediaplayer-doesnt-play-after-computer-sleeps
677+ InitSoundEffects ( ) ;
678+ }
679+ handled = true ;
680+ break ;
673681 }
674682
675683 return IntPtr . Zero ;
@@ -679,16 +687,6 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
679687
680688 #region Window Sound Effects
681689
682- private void SystemEvents_PowerModeChanged ( object sender , PowerModeChangedEventArgs e )
683- {
684- // Fix for sound not playing after sleep / hibernate
685- // https://stackoverflow.com/questions/64805186/mediaplayer-doesnt-play-after-computer-sleeps
686- if ( e . Mode == PowerModes . Resume )
687- {
688- InitSoundEffects ( ) ;
689- }
690- }
691-
692690 private void InitSoundEffects ( )
693691 {
694692 if ( _settings . WMPInstalled )
@@ -1443,7 +1441,6 @@ protected virtual void Dispose(bool disposing)
14431441 animationSoundWMP ? . Close ( ) ;
14441442 animationSoundWPF ? . Dispose ( ) ;
14451443 _viewModel . ActualApplicationThemeChanged -= ViewModel_ActualApplicationThemeChanged ;
1446- SystemEvents . PowerModeChanged -= SystemEvents_PowerModeChanged ;
14471444 }
14481445
14491446 _disposed = true ;
0 commit comments