diff --git a/Flow.Launcher/Helper/WindowsMediaPlayerHelper.cs b/Flow.Launcher/Helper/WindowsMediaPlayerHelper.cs new file mode 100644 index 000000000..2eec6c89b --- /dev/null +++ b/Flow.Launcher/Helper/WindowsMediaPlayerHelper.cs @@ -0,0 +1,11 @@ +using Microsoft.Win32; + +namespace Flow.Launcher.Helper; +internal static class WindowsMediaPlayerHelper +{ + internal static bool IsWindowsMediaPlayerInstalled() + { + using var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\MediaPlayer"); + return key.GetValue("Installation Directory") != null; + } +} diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index c05227d9a..7fc7a6325 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -158,7 +158,7 @@ Play a small sound when the search window opens Sound Effect Volume Adjust the volume of the sound effect - Windows Media Player is unavailable and is required for volume adjust. Please check your WMP installation + Windows Media Player is unavailable and is required for Flow's volume adjustment. Please check your installation if you need to adjust volume. Animation Use Animation in UI Animation Speed diff --git a/Flow.Launcher/MainWindow.xaml.cs b/Flow.Launcher/MainWindow.xaml.cs index bfc899988..2733413e7 100644 --- a/Flow.Launcher/MainWindow.xaml.cs +++ b/Flow.Launcher/MainWindow.xaml.cs @@ -12,7 +12,6 @@ using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.ViewModel; using Screen = System.Windows.Forms.Screen; -using ContextMenuStrip = System.Windows.Forms.ContextMenuStrip; using DragEventArgs = System.Windows.DragEventArgs; using KeyEventArgs = System.Windows.Input.KeyEventArgs; using NotifyIcon = System.Windows.Forms.NotifyIcon; @@ -24,12 +23,10 @@ using System.Windows.Data; using ModernWpf.Controls; using Key = System.Windows.Input.Key; using System.Media; -using static Flow.Launcher.ViewModel.SettingWindowViewModel; using DataObject = System.Windows.DataObject; using System.Windows.Media; using System.Windows.Interop; using System.Runtime.InteropServices; -using System.IO; namespace Flow.Launcher { @@ -47,10 +44,12 @@ namespace Flow.Launcher private ContextMenu contextMenu = new ContextMenu(); private MainViewModel _viewModel; private bool _animating; - MediaPlayer animationSoundWMP = new MediaPlayer(); - SoundPlayer animationSoundWPF = new SoundPlayer(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"); private bool isArrowKeyPressed = false; + private bool isWMPInstalled = true; + private MediaPlayer animationSoundWMP; + private SoundPlayer animationSoundWPF; + #endregion public MainWindow(Settings settings, MainViewModel mainVM) @@ -62,7 +61,7 @@ namespace Flow.Launcher InitializeComponent(); InitializePosition(); - animationSoundWMP.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav")); + InitSoundEffects(); DataObject.AddPastingHandler(QueryTextBox, OnPaste); } @@ -508,20 +507,35 @@ namespace Flow.Launcher windowsb.Begin(FlowMainWindow); } + private void InitSoundEffects() + { + isWMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled(); + if (isWMPInstalled) + { + animationSoundWMP = new MediaPlayer(); + animationSoundWMP.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav")); + } + else + { + animationSoundWPF = new SoundPlayer(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"); + } + } + private void SoundPlay() { - if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Windows Media Player", "wmplayer.exe"))) - { - animationSoundWPF.Play(); - } - else + if (isWMPInstalled) { animationSoundWMP.Position = TimeSpan.Zero; animationSoundWMP.Volume = _settings.SoundVolume / 100.0; animationSoundWMP.Play(); } + else + { + animationSoundWPF.Play(); + } } + private void OnMouseDown(object sender, MouseButtonEventArgs e) { if (e.ChangedButton == MouseButton.Left) DragMove(); diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index 963f20e1c..7f1ee0078 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -2,7 +2,6 @@ using Flow.Launcher.Core.Resource; using Flow.Launcher.Helper; using Flow.Launcher.Infrastructure; -using Flow.Launcher.Infrastructure.Hotkey; using Flow.Launcher.Infrastructure.UserSettings; using Flow.Launcher.Plugin; using Flow.Launcher.ViewModel; @@ -24,7 +23,6 @@ using KeyEventArgs = System.Windows.Input.KeyEventArgs; using MessageBox = System.Windows.MessageBox; using TextBox = System.Windows.Controls.TextBox; using ThemeManager = ModernWpf.ThemeManager; -using System.Diagnostics; namespace Flow.Launcher { @@ -42,7 +40,6 @@ namespace Flow.Launcher API = api; InitializePosition(); InitializeComponent(); - } #region General @@ -70,13 +67,13 @@ namespace Flow.Launcher private void CheckMediaPlayer() { - - if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Windows Media Player", "wmplayer2.exe"))) + if (!WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled()) { WMPWarning.Visibility = Visibility.Visible; VolumeAdjustCard.Visibility = Visibility.Collapsed; } } + private void SettingsWindowViewModelChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == nameof(viewModel.ExternalPlugins))