Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windows Media Player Warning #2683

Merged
merged 17 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions Flow.Launcher/Helper/WindowsMediaPlayerHelper.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
1 change: 1 addition & 0 deletions Flow.Launcher/Languages/en.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +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 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>
Expand Down
42 changes: 35 additions & 7 deletions Flow.Launcher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
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;
Expand All @@ -24,7 +23,6 @@
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;
Expand All @@ -46,9 +44,12 @@ public partial class MainWindow
private ContextMenu contextMenu = new ContextMenu();
private MainViewModel _viewModel;
private bool _animating;
MediaPlayer animationSound = new MediaPlayer();
private bool isArrowKeyPressed = false;

private bool isWMPInstalled = true;
private MediaPlayer animationSoundWMP;
private SoundPlayer animationSoundWPF;

#endregion

public MainWindow(Settings settings, MainViewModel mainVM)
Expand All @@ -60,7 +61,7 @@ public MainWindow(Settings settings, MainViewModel mainVM)
InitializeComponent();
InitializePosition();

animationSound.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
InitSoundEffects();

DataObject.AddPastingHandler(QueryTextBox, OnPaste);
}
Expand Down Expand Up @@ -140,9 +141,7 @@ private void OnLoaded(object sender, RoutedEventArgs _)
{
if (_settings.UseSound)
{
animationSound.Position = TimeSpan.Zero;
animationSound.Volume = _settings.SoundVolume / 100.0;
animationSound.Play();
SoundPlay();
}
UpdatePosition();
PreviewReset();
Expand Down Expand Up @@ -508,6 +507,35 @@ public void WindowAnimator()
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 (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();
Expand Down
36 changes: 35 additions & 1 deletion Flow.Launcher/SettingWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2519,7 +2519,7 @@
Width="Auto"
BorderThickness="1"
Style="{StaticResource SettingSeparatorStyle}" />
<Border Margin="0" BorderThickness="0">
<Border Margin="0" BorderThickness="0" Name="VolumeAdjustCard">
<Border.Style>
<Style BasedOn="{StaticResource SettingGroupBox}" TargetType="Border">
<Setter Property="Visibility" Value="Collapsed" />
Expand Down Expand Up @@ -2561,6 +2561,40 @@
</TextBlock>
</ItemsControl>
</Border>
<Border
Name="WMPWarning"
Padding="0,10"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Background="{DynamicResource InfoBarWarningBG}"
BorderBrush="{DynamicResource Color03B}"
BorderThickness="0,1,0,0"
CornerRadius="0 0 5 5"
Visibility="Collapsed">
<Grid VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="58" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ui:FontIcon
Grid.Column="0"
Margin="20,0,14,0"
VerticalAlignment="Center"
FontSize="15"
Foreground="{DynamicResource InfoBarWarningIcon}"
Glyph="&#xf167;" />
<TextBlock
Grid.Column="1"
Margin="0,0,0,2"
Padding="0,0,8,0"
HorizontalAlignment="Left"
FontSize="13"
FontWeight="SemiBold"
Foreground="{DynamicResource Color05B}"
Text="{DynamicResource SoundEffectWarning}"
TextWrapping="Wrap" />
</Grid>
</Border>
</StackPanel>
</Border>

Expand Down
12 changes: 10 additions & 2 deletions Flow.Launcher/SettingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,7 +40,6 @@ public SettingWindow(IPublicAPI api, SettingWindowViewModel viewModel)
API = api;
InitializePosition();
InitializeComponent();

}

#region General
Expand All @@ -63,9 +61,19 @@ private void OnLoaded(object sender, RoutedEventArgs e)

viewModel.PropertyChanged += new PropertyChangedEventHandler(SettingsWindowViewModelChanged);

CheckMediaPlayer();
InitializePosition();
}

private void CheckMediaPlayer()
{
if (!WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled())
{
WMPWarning.Visibility = Visibility.Visible;
VolumeAdjustCard.Visibility = Visibility.Collapsed;
}
}

private void SettingsWindowViewModelChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(viewModel.ExternalPlugins))
Expand Down