Skip to content

Commit 9d5f74c

Browse files
committed
Add sound effect volume
Signed-off-by: Florian Grabmeier <[email protected]>
1 parent 03bf15f commit 9d5f74c

File tree

6 files changed

+83
-15
lines changed

6 files changed

+83
-15
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: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
using System.Windows.Data;
2424
using ModernWpf.Controls;
2525
using Key = System.Windows.Input.Key;
26-
using System.Media;
27-
using static Flow.Launcher.ViewModel.SettingWindowViewModel;
26+
using System.Windows.Media;
2827

2928
namespace Flow.Launcher
3029
{
@@ -39,7 +38,7 @@ public partial class MainWindow
3938
private ContextMenu contextMenu;
4039
private MainViewModel _viewModel;
4140
private bool _animating;
42-
SoundPlayer animationSound = new SoundPlayer(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav");
41+
MediaPlayer animationSound = new MediaPlayer();
4342

4443
#endregion
4544

@@ -113,6 +112,8 @@ private void OnLoaded(object sender, RoutedEventArgs _)
113112
{
114113
if (_settings.UseSound)
115114
{
115+
animationSound.Open(new Uri(AppDomain.CurrentDomain.BaseDirectory + "Resources\\open.wav"));
116+
animationSound.Volume = _settings.SoundVolume / 100.0;
116117
animationSound.Play();
117118
}
118119
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}">
24952501
&#xe994;
2496-
</TextBlock>
2497-
</ItemsControl>
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}">
2547+
&#xe994;
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)