Only check WMP installation on load

This commit is contained in:
VictoriousRaptor 2024-05-19 20:13:37 +08:00
parent 5f68066181
commit 490bf59024
4 changed files with 39 additions and 17 deletions

View file

@ -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;
}
}

View file

@ -158,7 +158,7 @@
<system:String x:Key="SoundEffectTip">Play a small sound when the search window opens</system:String>
<system:String x:Key="SoundEffectVolume">Sound Effect Volume</system:String>
<system:String x:Key="SoundEffectVolumeTip">Adjust the volume of the sound effect</system:String>
<system:String x:Key="SoundEffectWarning">Windows Media Player is unavailable and is required for volume adjust. Please check your WMP installation</system:String>
<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>
<system:String x:Key="Animation">Animation</system:String>
<system:String x:Key="AnimationTip">Use Animation in UI</system:String>
<system:String x:Key="AnimationSpeed">Animation Speed</system:String>

View file

@ -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();

View file

@ -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))