25
25
using Flow . Launcher . Plugin . SharedCommands ;
26
26
using Flow . Launcher . Plugin . SharedModels ;
27
27
using Flow . Launcher . ViewModel ;
28
- using Microsoft . Win32 ;
29
28
using ModernWpf . Controls ;
30
29
using DataObject = System . Windows . DataObject ;
31
30
using Key = System . Windows . Input . Key ;
@@ -96,7 +95,6 @@ public MainWindow()
96
95
97
96
InitSoundEffects ( ) ;
98
97
DataObject . AddPastingHandler ( QueryTextBox , QueryTextBox_OnPaste ) ;
99
- SystemEvents . PowerModeChanged += SystemEvents_PowerModeChanged ;
100
98
_viewModel . ActualApplicationThemeChanged += ViewModel_ActualApplicationThemeChanged ;
101
99
}
102
100
@@ -670,6 +668,16 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
670
668
handled = true ;
671
669
}
672
670
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 ;
673
681
}
674
682
675
683
return IntPtr . Zero ;
@@ -679,16 +687,6 @@ private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref b
679
687
680
688
#region Window Sound Effects
681
689
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
-
692
690
private void InitSoundEffects ( )
693
691
{
694
692
if ( _settings . WMPInstalled )
@@ -1443,7 +1441,6 @@ protected virtual void Dispose(bool disposing)
1443
1441
animationSoundWMP ? . Close ( ) ;
1444
1442
animationSoundWPF ? . Dispose ( ) ;
1445
1443
_viewModel . ActualApplicationThemeChanged -= ViewModel_ActualApplicationThemeChanged ;
1446
- SystemEvents . PowerModeChanged -= SystemEvents_PowerModeChanged ;
1447
1444
}
1448
1445
1449
1446
_disposed = true ;
0 commit comments