Skip to content

Commit 0cb80c4

Browse files
authored
Merge pull request #2488 from flooxo/volume
feat: Add sound effect volume
2 parents 2796215 + 6057eae commit 0cb80c4

File tree

6 files changed

+86
-13
lines changed

6 files changed

+86
-13
lines changed

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public string Theme
5454
public bool UseGlyphIcons { get; set; } = true;
5555
public bool UseAnimation { get; set; } = true;
5656
public bool UseSound { get; set; } = true;
57+
public double SoundVolume { get; set; } = 50;
58+
5759
public bool UseClock { get; set; } = true;
5860
public bool UseDate { get; set; } = false;
5961
public string TimeFormat { get; set; } = "hh:mm tt";

Flow.Launcher/Languages/en.xaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@
156156
<system:String x:Key="ColorSchemeDark">Dark</system:String>
157157
<system:String x:Key="SoundEffect">Sound Effect</system:String>
158158
<system:String x:Key="SoundEffectTip">Play a small sound when the search window opens</system:String>
159+
<system:String x:Key="SoundEffectVolume">Sound Effect Volume</system:String>
160+
<system:String x:Key="SoundEffectVolumeTip">Adjust the volume of the sound effect</system:String>
159161
<system:String x:Key="Animation">Animation</system:String>
160162
<system:String x:Key="AnimationTip">Use Animation in UI</system:String>
161163
<system:String x:Key="AnimationSpeed">Animation Speed</system:String>

Flow.Launcher/MainWindow.xaml.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using System.Media;
2727
using static Flow.Launcher.ViewModel.SettingWindowViewModel;
2828
using DataObject = System.Windows.DataObject;
29+
using System.Windows.Media;
2930

3031
namespace Flow.Launcher
3132
{
@@ -40,7 +41,7 @@ public partial class MainWindow
4041
private ContextMenu contextMenu;
4142
private MainViewModel _viewModel;
4243
private bool _animating;
43-
SoundPlayer animationSound = new SoundPlayer(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav");
44+
MediaPlayer animationSound = new MediaPlayer();
4445

4546
#endregion
4647

@@ -52,6 +53,9 @@ public MainWindow(Settings settings, MainViewModel mainVM)
5253

5354
InitializeComponent();
5455
InitializePosition();
56+
57+
animationSound.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
58+
5559
DataObject.AddPastingHandler(QueryTextBox, OnPaste);
5660
}
5761

@@ -128,6 +132,8 @@ private void OnLoaded(object sender, RoutedEventArgs _)
128132
{
129133
if (_settings.UseSound)
130134
{
135+
animationSound.Position = TimeSpan.Zero;
136+
animationSound.Volume = _settings.SoundVolume / 100.0;
131137
animationSound.Play();
132138
}
133139
UpdatePosition();

Flow.Launcher/Resources/open.wav

25.2 KB
Binary file not shown.

Flow.Launcher/SettingWindow.xaml

Lines changed: 66 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,27 +2474,81 @@
24742474
</StackPanel>
24752475
</Border>
24762476

2477-
24782477
<Border
2479-
Margin="0"
2480-
BorderThickness="0"
2478+
Margin="0,12,0,12"
2479+
Padding="0"
2480+
CornerRadius="5"
24812481
Style="{DynamicResource SettingGroupBox}">
2482-
<ItemsControl Style="{StaticResource SettingGrid}">
2483-
<StackPanel Style="{StaticResource TextPanel}">
2484-
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource SoundEffect}" />
2485-
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{DynamicResource SoundEffectTip}" />
2486-
</StackPanel>
2487-
<ui:ToggleSwitch
2482+
<StackPanel Orientation="Vertical">
2483+
<Border
2484+
Margin="0"
2485+
BorderThickness="0"
2486+
Style="{DynamicResource SettingGroupBox}">
2487+
<ItemsControl Style="{StaticResource SettingGrid}">
2488+
<StackPanel Style="{StaticResource TextPanel}">
2489+
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource SoundEffect}" />
2490+
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{DynamicResource SoundEffectTip}" />
2491+
</StackPanel>
2492+
<ui:ToggleSwitch
2493+
x:Name="SoundEffect"
24882494
Grid.Row="0"
24892495
Grid.Column="2"
24902496
IsOn="{Binding UseSound, Mode=TwoWay}"
24912497
OffContent="{DynamicResource disable}"
24922498
OnContent="{DynamicResource enable}"
24932499
Style="{DynamicResource SideToggleSwitch}" />
2494-
<TextBlock Style="{StaticResource Glyph}">
2500+
<TextBlock Style="{StaticResource Glyph}">
2501+
&#xe7f5;
2502+
</TextBlock>
2503+
</ItemsControl>
2504+
</Border>
2505+
<Separator
2506+
Width="Auto"
2507+
BorderThickness="1"
2508+
Style="{StaticResource SettingSeparatorStyle}" />
2509+
<Border Margin="0" BorderThickness="0">
2510+
<Border.Style>
2511+
<Style BasedOn="{StaticResource SettingGroupBox}" TargetType="Border">
2512+
<Setter Property="Visibility" Value="Collapsed" />
2513+
<Style.Triggers>
2514+
<DataTrigger Binding="{Binding ElementName=SoundEffect, Path=IsOn}" Value="True">
2515+
<Setter Property="Visibility" Value="Visible" />
2516+
</DataTrigger>
2517+
</Style.Triggers>
2518+
</Style>
2519+
</Border.Style>
2520+
2521+
<ItemsControl Style="{StaticResource SettingGrid}">
2522+
<StackPanel Style="{StaticResource TextPanel}">
2523+
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource SoundEffectVolume}" />
2524+
<TextBlock Style="{DynamicResource SettingSubTitleLabel}" Text="{DynamicResource SoundEffectVolumeTip}" />
2525+
</StackPanel>
2526+
<StackPanel Grid.Column="2" Orientation="Horizontal">
2527+
<TextBlock
2528+
Width="Auto"
2529+
Margin="0,0,8,2"
2530+
VerticalAlignment="Center"
2531+
Foreground="{DynamicResource Color05B}"
2532+
Text="{Binding ElementName=SoundEffectValue, Path=Value, UpdateSourceTrigger=PropertyChanged}"
2533+
TextAlignment="Right" />
2534+
<Slider
2535+
Name="SoundEffectValue"
2536+
Width="250"
2537+
Margin="0,0,18,0"
2538+
VerticalAlignment="Center"
2539+
IsMoveToPointEnabled="True"
2540+
IsSnapToTickEnabled="True"
2541+
Maximum="100"
2542+
Minimum="0"
2543+
TickFrequency="1"
2544+
Value="{Binding SoundEffectVolume, Mode=TwoWay}" />
2545+
</StackPanel>
2546+
<TextBlock Style="{StaticResource Glyph}">
24952547
&#xe994;
2496-
</TextBlock>
2497-
</ItemsControl>
2548+
</TextBlock>
2549+
</ItemsControl>
2550+
</Border>
2551+
</StackPanel>
24982552
</Border>
24992553

25002554
<Border Margin="0,12,0,12" Style="{DynamicResource SettingGroupBox}">

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ public SettingWindowViewModel(Updater updater, IPortable portable)
6363
case nameof(Settings.PreviewHotkey):
6464
OnPropertyChanged(nameof(AlwaysPreviewToolTip));
6565
break;
66+
case nameof(Settings.SoundVolume):
67+
OnPropertyChanged(nameof(SoundEffectVolume));
68+
break;
6669
}
6770
};
6871

@@ -631,6 +634,12 @@ public bool UseSound
631634
set => Settings.UseSound = value;
632635
}
633636

637+
public double SoundEffectVolume
638+
{
639+
get => Settings.SoundVolume;
640+
set => Settings.SoundVolume = value;
641+
}
642+
634643
public bool UseClock
635644
{
636645
get => Settings.UseClock;

0 commit comments

Comments
 (0)