Skip to content

Commit f8d6f12

Browse files
authored
Merge branch 'dev' into 240513FixBindingErrors
2 parents 78d895e + 5afce95 commit f8d6f12

File tree

7 files changed

+93
-9
lines changed

7 files changed

+93
-9
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ public bool HideNotifyIcon
273273
public AnimationSpeeds AnimationSpeed { get; set; } = AnimationSpeeds.Medium;
274274
public int CustomAnimationLength { get; set; } = 360;
275275

276+
[JsonIgnore]
277+
public bool WMPInstalled { get; set; } = true;
278+
276279

277280
// This needs to be loaded last by staying at the bottom
278281
public PluginsSettings PluginSettings { get; set; } = new PluginsSettings();

Flow.Launcher/App.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
6262

6363
_settingsVM = new SettingWindowViewModel(_updater, _portable);
6464
_settings = _settingsVM.Settings;
65+
_settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled();
6566

6667
AbstractPluginEnvironment.PreStartPluginExecutablePathUpdate(_settings);
6768

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +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 Flow's volume adjustment. Please check your installation if you need to adjust volume.</system:String>
161162
<system:String x:Key="Animation">Animation</system:String>
162163
<system:String x:Key="AnimationTip">Use Animation in UI</system:String>
163164
<system:String x:Key="AnimationSpeed">Animation Speed</system:String>

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 32 additions & 7 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,7 +23,6 @@
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;
@@ -46,9 +44,11 @@ public partial class MainWindow
4644
private ContextMenu contextMenu = new ContextMenu();
4745
private MainViewModel _viewModel;
4846
private bool _animating;
49-
MediaPlayer animationSound = new MediaPlayer();
5047
private bool isArrowKeyPressed = false;
5148

49+
private MediaPlayer animationSoundWMP;
50+
private SoundPlayer animationSoundWPF;
51+
5252
#endregion
5353

5454
public MainWindow(Settings settings, MainViewModel mainVM)
@@ -60,7 +60,7 @@ public MainWindow(Settings settings, MainViewModel mainVM)
6060
InitializeComponent();
6161
InitializePosition();
6262

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

6565
DataObject.AddPastingHandler(QueryTextBox, OnPaste);
6666
}
@@ -140,9 +140,7 @@ private void OnLoaded(object sender, RoutedEventArgs _)
140140
{
141141
if (_settings.UseSound)
142142
{
143-
animationSound.Position = TimeSpan.Zero;
144-
animationSound.Volume = _settings.SoundVolume / 100.0;
145-
animationSound.Play();
143+
SoundPlay();
146144
}
147145
UpdatePosition();
148146
PreviewReset();
@@ -508,6 +506,33 @@ public void WindowAnimator()
508506
windowsb.Begin(FlowMainWindow);
509507
}
510508

509+
private void InitSoundEffects()
510+
{
511+
if (_settings.WMPInstalled)
512+
{
513+
animationSoundWMP = new MediaPlayer();
514+
animationSoundWMP.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
515+
}
516+
else
517+
{
518+
animationSoundWPF = new SoundPlayer(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav");
519+
}
520+
}
521+
522+
private void SoundPlay()
523+
{
524+
if (_settings.WMPInstalled)
525+
{
526+
animationSoundWMP.Position = TimeSpan.Zero;
527+
animationSoundWMP.Volume = _settings.SoundVolume / 100.0;
528+
animationSoundWMP.Play();
529+
}
530+
else
531+
{
532+
animationSoundWPF.Play();
533+
}
534+
}
535+
511536
private void OnMouseDown(object sender, MouseButtonEventArgs e)
512537
{
513538
if (e.ChangedButton == MouseButton.Left) DragMove();

Flow.Launcher/SettingPages/ViewModels/SettingsPaneThemeViewModel.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,22 @@ public List<AnimationSpeed> AnimationSpeeds
181181
return speeds;
182182
}
183183
}
184-
185184
public bool UseSound
186185
{
187186
get => Settings.UseSound;
188187
set => Settings.UseSound = value;
189188
}
190189

190+
public bool ShowWMPWarning
191+
{
192+
get => !Settings.WMPInstalled && UseSound;
193+
}
194+
195+
public bool EnableVolumeAdjustment
196+
{
197+
get => Settings.WMPInstalled;
198+
}
199+
191200
public double SoundEffectVolume
192201
{
193202
get => Settings.SoundVolume;

Flow.Launcher/SettingPages/Views/SettingsPaneTheme.xaml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,14 @@
442442
<cc:Card
443443
Title="{DynamicResource SoundEffectVolume}"
444444
Icon="&#xe994;"
445+
IsEnabled="{Binding EnableVolumeAdjustment}"
445446
Sub="{DynamicResource SoundEffectVolumeTip}"
446447
Visibility="{Binding UseSound, Converter={StaticResource BoolToVisibilityConverter}}">
447448
<StackPanel Orientation="Horizontal">
448449
<TextBlock
449450
Margin="0,0,8,0"
450451
VerticalAlignment="Center"
451452
Text="{Binding SoundEffectVolume}" />
452-
453453
<Slider
454454
Width="250"
455455
VerticalAlignment="Center"
@@ -462,6 +462,40 @@
462462
</StackPanel>
463463
</cc:Card>
464464
</cc:CardGroup>
465+
<Border
466+
Name="WMPWarning"
467+
Padding="0,10"
468+
HorizontalAlignment="Stretch"
469+
VerticalAlignment="Center"
470+
Background="{DynamicResource InfoBarWarningBG}"
471+
BorderBrush="{DynamicResource Color03B}"
472+
BorderThickness="0,1,0,0"
473+
CornerRadius="5 5 5 5"
474+
Visibility="{Binding ShowWMPWarning, Converter={StaticResource BoolToVisibilityConverter}}">
475+
<Grid VerticalAlignment="Center">
476+
<Grid.ColumnDefinitions>
477+
<ColumnDefinition Width="58" />
478+
<ColumnDefinition Width="*" />
479+
</Grid.ColumnDefinitions>
480+
<ui:FontIcon
481+
Grid.Column="0"
482+
Margin="20,0,14,0"
483+
VerticalAlignment="Center"
484+
FontSize="15"
485+
Foreground="{DynamicResource InfoBarWarningIcon}"
486+
Glyph="&#xf167;" />
487+
<TextBlock
488+
Grid.Column="1"
489+
Margin="0,0,0,2"
490+
Padding="0,0,8,0"
491+
HorizontalAlignment="Left"
492+
FontSize="13"
493+
FontWeight="SemiBold"
494+
Foreground="{DynamicResource Color05B}"
495+
Text="{DynamicResource SoundEffectWarning}"
496+
TextWrapping="Wrap" />
497+
</Grid>
498+
</Border>
465499

466500
<!-- Settings color scheme -->
467501
<cc:Card

0 commit comments

Comments
 (0)