diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index e243549e3..46eeb2adc 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -22,6 +22,7 @@ using Flow.Launcher.Infrastructure.Image; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin.SharedCommands; using Flow.Launcher.ViewModel; +using Microsoft.Win32; using ModernWpf.Controls; using DataObject = System.Windows.DataObject; using Key = System.Windows.Input.Key; @@ -88,6 +89,8 @@ namespace Flow.Launcher InitSoundEffects(); DataObject.AddPastingHandler(QueryTextBox, QueryTextBox_OnPaste); + + SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged; } #endregion @@ -540,16 +543,29 @@ namespace Flow.Launcher #region Window Sound Effects + private void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e) + { + // Fix for sound not playing after sleep / hibernate + // https://stackoverflow.com/questions/64805186/mediaplayer-doesnt-play-after-computer-sleeps + if (e.Mode == PowerModes.Resume) + { + InitSoundEffects(); + } + } + private void InitSoundEffects() { if (_settings.WMPInstalled) { + animationSoundWMP?.Close(); animationSoundWMP = new MediaPlayer(); animationSoundWMP.Open(new Uri(AppContext.BaseDirectory + "Resources\\open.wav")); } else { + animationSoundWPF?.Dispose(); animationSoundWPF = new SoundPlayer(AppContext.BaseDirectory + "Resources\\open.wav"); + animationSoundWPF.Load(); } } @@ -816,7 +832,7 @@ namespace Flow.Launcher { Name = progressBarAnimationName, Storyboard = progressBarStoryBoard }; - + var stopStoryboard = new StopStoryboard() { BeginStoryboardName = progressBarAnimationName @@ -837,7 +853,7 @@ namespace Flow.Launcher progressStyle.Triggers.Add(trigger); ProgressBar.Style = progressStyle; - + _viewModel.ProgressBarVisibility = Visibility.Hidden; } @@ -885,7 +901,7 @@ namespace Flow.Launcher Duration = TimeSpan.FromMilliseconds(animationLength), FillBehavior = FillBehavior.HoldEnd }; - + var rightMargin = GetThicknessFromStyle(ClockPanel.Style, new Thickness(0, 0, DefaultRightMargin, 0)).Right; var thicknessAnimation = new ThicknessAnimation @@ -913,10 +929,10 @@ namespace Flow.Launcher clocksb.Children.Add(ClockOpacity); iconsb.Children.Add(IconMotion); iconsb.Children.Add(IconOpacity); - + _settings.WindowLeft = Left; _isArrowKeyPressed = false; - + clocksb.Begin(ClockPanel); iconsb.Begin(SearchIcon); } @@ -1088,7 +1104,7 @@ namespace Flow.Launcher { e.Handled = true; } - + #endregion #region Placeholder @@ -1140,7 +1156,7 @@ namespace Flow.Launcher } #endregion - + #region Search Delay private void QueryTextBox_TextChanged1(object sender, TextChangedEventArgs e) @@ -1162,6 +1178,9 @@ namespace Flow.Launcher { _hwndSource?.Dispose(); _notifyIcon?.Dispose(); + animationSoundWMP?.Close(); + animationSoundWPF?.Dispose(); + SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged; } _disposed = true;