Merge pull request #2683 from onesounds/AlertWithoutWMP

Add Windows Media Player Warning
This commit is contained in:
VictoriousRaptor 2024-05-23 23:11:20 +08:00 committed by GitHub
commit 5afce95a75
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 168 additions and 81 deletions

View file

@ -273,6 +273,9 @@ namespace Flow.Launcher.Infrastructure.UserSettings
public AnimationSpeeds AnimationSpeed { get; set; } = AnimationSpeeds.Medium;
public int CustomAnimationLength { get; set; } = 360;
[JsonIgnore]
public bool WMPInstalled { get; set; } = true;
// This needs to be loaded last by staying at the bottom
public PluginsSettings PluginSettings { get; set; } = new PluginsSettings();

View file

@ -62,6 +62,7 @@ namespace Flow.Launcher
_settingsVM = new SettingWindowViewModel(_updater, _portable);
_settings = _settingsVM.Settings;
_settings.WMPInstalled = WindowsMediaPlayerHelper.IsWindowsMediaPlayerInstalled();
AbstractPluginEnvironment.PreStartPluginExecutablePathUpdate(_settings);

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,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>

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,7 +23,6 @@ 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;
@ -46,9 +44,11 @@ namespace Flow.Launcher
private ContextMenu contextMenu = new ContextMenu();
private MainViewModel _viewModel;
private bool _animating;
MediaPlayer animationSound = new MediaPlayer();
private bool isArrowKeyPressed = false;
private MediaPlayer animationSoundWMP;
private SoundPlayer animationSoundWPF;
#endregion
public MainWindow(Settings settings, MainViewModel mainVM)
@ -60,7 +60,7 @@ namespace Flow.Launcher
InitializeComponent();
InitializePosition();
animationSound.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
InitSoundEffects();
DataObject.AddPastingHandler(QueryTextBox, OnPaste);
}
@ -140,9 +140,7 @@ namespace Flow.Launcher
{
if (_settings.UseSound)
{
animationSound.Position = TimeSpan.Zero;
animationSound.Volume = _settings.SoundVolume / 100.0;
animationSound.Play();
SoundPlay();
}
UpdatePosition();
PreviewReset();
@ -508,6 +506,33 @@ namespace Flow.Launcher
windowsb.Begin(FlowMainWindow);
}
private void InitSoundEffects()
{
if (_settings.WMPInstalled)
{
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 (_settings.WMPInstalled)
{
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

@ -181,13 +181,22 @@ public partial class SettingsPaneThemeViewModel : BaseModel
return speeds;
}
}
public bool UseSound
{
get => Settings.UseSound;
set => Settings.UseSound = value;
}
public bool ShowWMPWarning
{
get => !Settings.WMPInstalled && UseSound;
}
public bool EnableVolumeAdjustment
{
get => Settings.WMPInstalled;
}
public double SoundEffectVolume
{
get => Settings.SoundVolume;

View file

@ -4,12 +4,12 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:Flow.Launcher.Resources.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:ext="clr-namespace:Flow.Launcher.Resources.MarkupExtensions"
xmlns:flowlauncher="clr-namespace:Flow.Launcher"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:userSettings="clr-namespace:Flow.Launcher.Infrastructure.UserSettings;assembly=Flow.Launcher.Infrastructure"
xmlns:viewModels="clr-namespace:Flow.Launcher.SettingPages.ViewModels"
xmlns:ext="clr-namespace:Flow.Launcher.Resources.MarkupExtensions"
Title="Theme"
d:DataContext="{d:DesignInstance viewModels:SettingsPaneThemeViewModel}"
d:DesignHeight="450"
@ -25,22 +25,22 @@
</ResourceDictionary>
</ui:Page.Resources>
<ScrollViewer
Padding="6 0 24 0"
Padding="6,0,24,0"
CanContentScroll="True"
FontSize="14"
VirtualizingStackPanel.IsVirtualizing="True"
VirtualizingStackPanel.ScrollUnit="Pixel">
<StackPanel>
<!-- Page title -->
<!-- Page title -->
<TextBlock
Margin="5 23 0 5"
Margin="5,23,0,5"
FontSize="30"
Style="{StaticResource PageTitle}"
Text="{DynamicResource appearance}"
TextAlignment="left"
Visibility="Collapsed" />
<!-- Theme preview -->
<!-- Theme preview -->
<StackPanel
Height="350"
Margin="0"
@ -71,25 +71,25 @@
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<!-- Query TextBox -->
<!-- Query TextBox -->
<TextBox
x:Name="QueryTextBox"
Grid.Row="0"
IsReadOnly="True"
Style="{DynamicResource QueryBoxStyle}"
Text="{DynamicResource hiThere}" />
<!-- Clock panel -->
<!-- Clock panel -->
<StackPanel
Grid.Row="0"
Style="{DynamicResource ClockPanel}"
Visibility="Visible">
<!-- Clock TextBox -->
<!-- Clock TextBox -->
<TextBlock
x:Name="ClockBox"
Style="{DynamicResource ClockBox}"
Text="{Binding ClockText}"
Visibility="{Binding Settings.UseClock, Converter={StaticResource BoolToVisibilityConverter}}" />
<!-- Date TextBox -->
<!-- Date TextBox -->
<TextBlock
x:Name="DateBox"
Style="{DynamicResource DateBox}"
@ -122,19 +122,19 @@
</StackPanel>
</StackPanel>
<!-- Drop shadow effect -->
<!-- Drop shadow effect -->
<cc:Card
Icon="&#xeb91;"
Title="{DynamicResource queryWindowShadowEffect}"
Sub="{DynamicResource shadowEffectCPUUsage}"
Margin="0 4 0 0">
Margin="0,4,0,0"
Icon="&#xeb91;"
Sub="{DynamicResource shadowEffectCPUUsage}">
<ui:ToggleSwitch
IsOn="{Binding DropShadowEffect}"
OffContent="{DynamicResource disable}"
OnContent="{DynamicResource enable}" />
</cc:Card>
<!-- Window width size -->
<!-- Window width size -->
<cc:Card
Title="{DynamicResource windowWidthSize}"
Icon="&#xe740;"
@ -142,7 +142,7 @@
<StackPanel Orientation="Horizontal">
<TextBlock
Width="Auto"
Margin="0 0 8 2"
Margin="0,0,8,2"
VerticalAlignment="Center"
Foreground="{DynamicResource Color05B}"
Text="{Binding WindowWidthSize}"
@ -159,10 +159,10 @@
</StackPanel>
</cc:Card>
<!-- Theme -->
<!-- Theme -->
<Border
Height="64"
Margin="0 8 0 0"
Margin="0,8,0,0"
CornerRadius="5 5 0 0"
Style="{DynamicResource SettingGroupBox}">
<ItemsControl Style="{StaticResource SettingGrid}">
@ -179,7 +179,7 @@
Margin="0"
Padding="0"
HorizontalAlignment="Stretch"
BorderThickness="1 0 1 1"
BorderThickness="1,0,1,1"
CornerRadius="0 0 5 5"
Style="{DynamicResource SettingGroupBox}">
<ListBox
@ -195,10 +195,8 @@
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Background" Value="Transparent" />
<Setter Property="HorizontalContentAlignment"
Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="VerticalContentAlignment"
Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}" />
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="4" />
<Setter Property="Template">
@ -209,13 +207,13 @@
Padding="{TemplateBinding Padding}"
Background="{DynamicResource Color12B}"
BorderBrush="{DynamicResource Color03B}"
BorderThickness="1 1 1 0"
BorderThickness="1,1,1,0"
CornerRadius="4"
SnapsToDevicePixels="true">
<Border
x:Name="Bd2"
BorderBrush="{DynamicResource Color14B}"
BorderThickness="0 0 0 2"
BorderThickness="0,0,0,2"
CornerRadius="4">
<ContentPresenter
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
@ -225,15 +223,12 @@
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Bd" Property="Background"
Value="{DynamicResource ThemeHoverButton}" />
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource ThemeHoverButton}" />
</Trigger>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="Bd" Property="Background"
Value="{DynamicResource ToggleSwitchFillOn}" />
<Setter TargetName="Bd" Property="Background" Value="{DynamicResource ToggleSwitchFillOn}" />
<Setter TargetName="Bd2" Property="BorderThickness" Value="0" />
<Setter TargetName="Bd2" Property="TextElement.Foreground"
Value="{DynamicResource Color02B}" />
<Setter TargetName="Bd2" Property="TextElement.Foreground" Value="{DynamicResource Color02B}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
@ -256,7 +251,7 @@
<TextBlock
x:Name="ThemeName"
Margin="0"
Padding="14 12"
Padding="14,12"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Focusable="True"
@ -278,21 +273,23 @@
<cc:HyperLink
Margin="10"
HorizontalAlignment="Right"
Uri="{Binding LinkThemeGallery}"
Text="{DynamicResource browserMoreThemes}" />
Text="{DynamicResource browserMoreThemes}"
Uri="{Binding LinkThemeGallery}" />
<!-- Fonts and icons -->
<cc:CardGroup Margin="0 30 0 0">
<cc:Card Icon="&#xf6b8;" Title="{DynamicResource useGlyphUI}"
Sub="{DynamicResource useGlyphUIEffect}">
<!-- Fonts and icons -->
<cc:CardGroup Margin="0,30,0,0">
<cc:Card
Title="{DynamicResource useGlyphUI}"
Icon="&#xf6b8;"
Sub="{DynamicResource useGlyphUIEffect}">
<ui:ToggleSwitch
IsOn="{Binding UseGlyphIcons}"
OffContent="{DynamicResource disable}"
OnContent="{DynamicResource enable}" />
</cc:Card>
<cc:Card Icon="&#xe990;" Title="{DynamicResource queryBoxFont}">
<cc:Card Title="{DynamicResource queryBoxFont}" Icon="&#xe990;">
<StackPanel Orientation="Horizontal">
<ComboBox
Width="180"
@ -301,7 +298,7 @@
SelectedItem="{Binding SelectedQueryBoxFont}" />
<ComboBox
Width="130"
Margin="10 0 0 0"
Margin="10,0,0,0"
ItemsSource="{Binding SelectedQueryBoxFont.FamilyTypefaces}"
SelectedItem="{Binding SelectedQueryBoxFontFaces}">
<ComboBox.ItemTemplate>
@ -319,7 +316,7 @@
</StackPanel>
</cc:Card>
<cc:Card Icon="&#xe8fd;" Title="{DynamicResource resultItemFont}">
<cc:Card Title="{DynamicResource resultItemFont}" Icon="&#xe8fd;">
<StackPanel Orientation="Horizontal">
<ComboBox
Width="180"
@ -328,7 +325,7 @@
SelectedItem="{Binding SelectedResultFont}" />
<ComboBox
Width="130"
Margin="10 0 0 0"
Margin="10,0,0,0"
ItemsSource="{Binding SelectedResultFont.FamilyTypefaces}"
SelectedItem="{Binding SelectedResultFontFaces}">
<ComboBox.ItemTemplate>
@ -347,9 +344,9 @@
</cc:Card>
</cc:CardGroup>
<!-- Time and date -->
<cc:CardGroup Margin="0 24 0 0">
<cc:Card Icon="&#xec92;" Title="{DynamicResource Clock}">
<!-- Time and date -->
<cc:CardGroup Margin="0,24,0,0">
<cc:Card Title="{DynamicResource Clock}" Icon="&#xec92;">
<StackPanel Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
@ -358,7 +355,7 @@
Text="{Binding ClockText}" />
<ComboBox
MinWidth="180"
Margin="10 0 18 0"
Margin="10,0,18,0"
VerticalAlignment="Center"
FontSize="14"
ItemsSource="{Binding TimeFormatList}"
@ -370,7 +367,7 @@
</StackPanel>
</cc:Card>
<cc:Card Icon="&#xe787;" Title="{DynamicResource Date}">
<cc:Card Title="{DynamicResource Date}" Icon="&#xe787;">
<StackPanel Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
@ -379,7 +376,7 @@
Text="{Binding DateText}" />
<ComboBox
MinWidth="180"
Margin="10 0 18 0"
Margin="10,0,18,0"
VerticalAlignment="Center"
FontSize="14"
ItemsSource="{Binding DateFormatList}"
@ -392,11 +389,11 @@
</cc:Card>
</cc:CardGroup>
<!-- Animation -->
<cc:CardGroup Margin="0 11 0 0">
<!-- Animation -->
<cc:CardGroup Margin="0,11,0,0">
<cc:Card
Icon="&#xedb5;"
Title="{DynamicResource Animation}"
Icon="&#xedb5;"
Sub="{DynamicResource AnimationTip}">
<ui:ToggleSwitch
IsOn="{Binding UseAnimation}"
@ -404,8 +401,8 @@
OnContent="{DynamicResource enable}" />
</cc:Card>
<cc:Card
Icon="&#xe916;"
Title="{DynamicResource AnimationSpeed}"
Icon="&#xe916;"
Sub="{DynamicResource AnimationSpeedTip}"
Visibility="{Binding UseAnimation, Converter={StaticResource BoolToVisibilityConverter}}">
<StackPanel Orientation="Horizontal">
@ -419,35 +416,38 @@
SelectedValuePath="Value" />
<TextBox
Margin="18 0 0 0"
MinWidth="80"
Margin="18,0,0,0"
Text="{Binding Settings.CustomAnimationLength}"
TextWrapping="NoWrap"
Visibility="{ext:VisibleWhen
{Binding Settings.AnimationSpeed},
IsEqualTo={x:Static userSettings:AnimationSpeeds.Custom}}" />
Visibility="{ext:VisibleWhen {Binding Settings.AnimationSpeed},
IsEqualTo={x:Static userSettings:AnimationSpeeds.Custom}}" />
</StackPanel>
</cc:Card>
</cc:CardGroup>
<!-- SFX -->
<cc:CardGroup Margin="0 11 0 0">
<cc:Card Icon="&#xe7f5;" Title="{DynamicResource SoundEffect}"
Sub="{DynamicResource SoundEffectTip}">
<!-- SFX -->
<cc:CardGroup Margin="0,11,0,0">
<cc:Card
Title="{DynamicResource SoundEffect}"
Icon="&#xe7f5;"
Sub="{DynamicResource SoundEffectTip}">
<ui:ToggleSwitch
IsOn="{Binding UseSound}"
OffContent="{DynamicResource disable}"
OnContent="{DynamicResource enable}" />
</cc:Card>
<cc:Card Icon="&#xe994;" Title="{DynamicResource SoundEffectVolume}"
Sub="{DynamicResource SoundEffectVolumeTip}"
Visibility="{Binding UseSound, Converter={StaticResource BoolToVisibilityConverter}}">
<cc:Card
Title="{DynamicResource SoundEffectVolume}"
Icon="&#xe994;"
IsEnabled="{Binding EnableVolumeAdjustment}"
Sub="{DynamicResource SoundEffectVolumeTip}"
Visibility="{Binding UseSound, Converter={StaticResource BoolToVisibilityConverter}}">
<StackPanel Orientation="Horizontal">
<TextBlock
Margin="0 0 8 0"
Margin="0,0,8,0"
VerticalAlignment="Center"
Text="{Binding SoundEffectVolume}" />
<Slider
Width="250"
VerticalAlignment="Center"
@ -460,9 +460,46 @@
</StackPanel>
</cc:Card>
</cc:CardGroup>
<Border
Name="WMPWarning"
Padding="0,10"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Background="{DynamicResource InfoBarWarningBG}"
BorderBrush="{DynamicResource Color03B}"
BorderThickness="0,1,0,0"
CornerRadius="5 5 5 5"
Visibility="{Binding ShowWMPWarning, Converter={StaticResource BoolToVisibilityConverter}}">
<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>
<!-- Settings color scheme -->
<cc:Card Icon="&#xe793;" Title="{DynamicResource ColorScheme}" Margin="0 11 0 0">
<!-- Settings color scheme -->
<cc:Card
Title="{DynamicResource ColorScheme}"
Margin="0,11,0,0"
Icon="&#xe793;">
<ComboBox
MinWidth="180"
DisplayMemberPath="Display"
@ -470,23 +507,23 @@
ItemsSource="{Binding ColorSchemes}"
SelectedValue="{Binding Settings.ColorScheme}"
SelectedValuePath="Value"
SelectionChanged="Selector_OnSelectionChanged"/>
SelectionChanged="Selector_OnSelectionChanged" />
</cc:Card>
<!-- Theme folder -->
<cc:Card Icon="&#xe838;" Title="{DynamicResource ThemeFolder}">
<!-- Theme folder -->
<cc:Card Title="{DynamicResource ThemeFolder}" Icon="&#xe838;">
<Button
MinWidth="180"
Command="{Binding OpenThemesFolderCommand}"
Content="{DynamicResource OpenThemeFolder}" />
</cc:Card>
<!-- How to create theme link -->
<!-- How to create theme link -->
<cc:HyperLink
Margin="10 10 10 28"
Margin="10,10,10,28"
HorizontalAlignment="Right"
Uri="{Binding LinkHowToCreateTheme}"
Text="{DynamicResource howToCreateTheme}" />
Text="{DynamicResource howToCreateTheme}"
Uri="{Binding LinkHowToCreateTheme}" />
</StackPanel>
</ScrollViewer>
</ui:Page>