Skip to content

Commit 490bf59

Browse files
Only check WMP installation on load
1 parent 5f68066 commit 490bf59

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.Win32;
2+
3+
namespace Flow.Launcher.Helper;
4+
internal static class WindowsMediaPlayerHelper
5+
{
6+
internal static bool IsWindowsMediaPlayerInstalled()
7+
{
8+
using var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\MediaPlayer");
9+
return key.GetValue("Installation Directory") != null;
10+
}
11+
}

Flow.Launcher/Languages/en.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
<system:String x:Key="SoundEffectTip">Play a small sound when the search window opens</system:String>
159159
<system:String x:Key="SoundEffectVolume">Sound Effect Volume</system:String>
160160
<system:String x:Key="SoundEffectVolumeTip">Adjust the volume of the sound effect</system:String>
161-
<system:String x:Key="SoundEffectWarning">Windows Media Player is unavailable and is required for volume adjust. Please check your WMP installation</system:String>
161+
<system:String x:Key="SoundEffectWarning">Windows Media Player is unavailable and is required for Flow's volume adjustment. Please check your installation if you need to adjust volume.</system:String>
162162
<system:String x:Key="Animation">Animation</system:String>
163163
<system:String x:Key="AnimationTip">Use Animation in UI</system:String>
164164
<system:String x:Key="AnimationSpeed">Animation Speed</system:String>

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using Flow.Launcher.Infrastructure.UserSettings;
1313
using Flow.Launcher.ViewModel;
1414
using Screen = System.Windows.Forms.Screen;
15-
using ContextMenuStrip = System.Windows.Forms.ContextMenuStrip;
1615
using DragEventArgs = System.Windows.DragEventArgs;
1716
using KeyEventArgs = System.Windows.Input.KeyEventArgs;
1817
using NotifyIcon = System.Windows.Forms.NotifyIcon;
@@ -24,12 +23,10 @@
2423
using ModernWpf.Controls;
2524
using Key = System.Windows.Input.Key;
2625
using System.Media;
27-
using static Flow.Launcher.ViewModel.SettingWindowViewModel;
2826
using DataObject = System.Windows.DataObject;
2927
using System.Windows.Media;
3028
using System.Windows.Interop;
3129
using System.Runtime.InteropServices;
32-
using System.IO;
3330

3431
namespace Flow.Launcher
3532
{
@@ -47,10 +44,12 @@ public partial class MainWindow
4744
private ContextMenu contextMenu = new ContextMenu();
4845
private MainViewModel _viewModel;
4946
private bool _animating;
50-
MediaPlayer animationSoundWMP = new MediaPlayer();
51-
SoundPlayer animationSoundWPF = new SoundPlayer(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav");
5247
private bool isArrowKeyPressed = false;
5348

49+
private bool isWMPInstalled = true;
50+
private MediaPlayer animationSoundWMP;
51+
private SoundPlayer animationSoundWPF;
52+
5453
#endregion
5554

5655
public MainWindow(Settings settings, MainViewModel mainVM)
@@ -62,7 +61,7 @@ public MainWindow(Settings settings, MainViewModel mainVM)
6261
InitializeComponent();
6362
InitializePosition();
6463

65-
animationSoundWMP.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
64+
InitSoundEffects();
6665

6766
DataObject.AddPastingHandler(QueryTextBox, OnPaste);
6867
}
@@ -508,20 +507,35 @@ public void WindowAnimator()
508507
windowsb.Begin(FlowMainWindow);
509508
}
510509

511-
private void SoundPlay()
510+
private void InitSoundEffects()
512511
{
513-
514-
if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Windows Media Player", "wmplayer.exe")))
512+
isWMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled();
513+
if (isWMPInstalled)
515514
{
516-
animationSoundWPF.Play();
515+
animationSoundWMP = new MediaPlayer();
516+
animationSoundWMP.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
517517
}
518518
else
519+
{
520+
animationSoundWPF = new SoundPlayer(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav");
521+
}
522+
}
523+
524+
private void SoundPlay()
525+
{
526+
527+
if (isWMPInstalled)
519528
{
520529
animationSoundWMP.Position = TimeSpan.Zero;
521530
animationSoundWMP.Volume = _settings.SoundVolume / 100.0;
522531
animationSoundWMP.Play();
523532
}
533+
else
534+
{
535+
animationSoundWPF.Play();
536+
}
524537
}
538+
525539
private void OnMouseDown(object sender, MouseButtonEventArgs e)
526540
{
527541
if (e.ChangedButton == MouseButton.Left) DragMove();

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Flow.Launcher.Core.Resource;
33
using Flow.Launcher.Helper;
44
using Flow.Launcher.Infrastructure;
5-
using Flow.Launcher.Infrastructure.Hotkey;
65
using Flow.Launcher.Infrastructure.UserSettings;
76
using Flow.Launcher.Plugin;
87
using Flow.Launcher.ViewModel;
@@ -24,7 +23,6 @@
2423
using MessageBox = System.Windows.MessageBox;
2524
using TextBox = System.Windows.Controls.TextBox;
2625
using ThemeManager = ModernWpf.ThemeManager;
27-
using System.Diagnostics;
2826

2927
namespace Flow.Launcher
3028
{
@@ -42,7 +40,6 @@ public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
4240
API = api;
4341
InitializePosition();
4442
InitializeComponent();
45-
4643
}
4744

4845
#region General
@@ -70,13 +67,13 @@ private void OnLoaded(object sender, RoutedEventArgs e)
7067

7168
private void CheckMediaPlayer()
7269
{
73-
74-
if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Windows Media Player", "wmplayer2.exe")))
70+
if (!WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled())
7571
{
7672
WMPWarning.Visibility = Visibility.Visible;
7773
VolumeAdjustCard.Visibility = Visibility.Collapsed;
7874
}
7975
}
76+
8077
private void SettingsWindowViewModelChanged(object sender, PropertyChangedEventArgs e)
8178
{
8279
if (e.PropertyName == nameof(viewModel.ExternalPlugins))

0 commit comments

Comments
 (0)