Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
<package pattern="*" />
</packageSource>
</packageSourceMapping>
</configuration>
</configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<PrecompiledHeaderOutputFile>$(IntDir)pch.pch</PrecompiledHeaderOutputFile>
<WarningLevel>Level4</WarningLevel>
<AdditionalOptions>%(AdditionalOptions) /bigobj</AdditionalOptions>
<PreprocessorDefinitions>_WINRT_DLL;WINRT_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_WINRT_DLL;WINRT_LEAN_AND_MEAN;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>../../..;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalUsingDirectories>$(WindowsSDK_WindowsMetadata);$(AdditionalUsingDirectories)</AdditionalUsingDirectories>
</ClCompile>
Expand Down
48 changes: 48 additions & 0 deletions src/modules/launcher/PowerLauncher/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reactive.Linq;
using System.Runtime.InteropServices;
Expand Down Expand Up @@ -44,8 +45,16 @@ public partial class MainWindow : IDisposable
private bool _deletePressed;
private HwndSource _hwndSource;
private Timer _firstDeleteTimer = new Timer();
private bool _loadedAtLeastOnce;
private bool _coldStateHotkeyPressed;
private bool _disposedValue;

[DllImport("winmm.dll", CharSet = CharSet.Unicode)]
private static extern bool PlaySound(string lpszName, IntPtr hModule, uint dwFlags);

private static readonly uint SndFilename = 0x00020000;
private static readonly uint SndAsync = 0x00000001;

private IDisposable _reactiveSubscription;
private Point _mouseDownPosition;
private ResultViewModel _mouseDownResultViewModel;
Expand Down Expand Up @@ -251,6 +260,7 @@ private void OnLoaded(object sender, RoutedEventArgs e)
_viewModel.SetFontSize();

BringProcessToForeground();
_loadedAtLeastOnce = true;
}

private void SetupSearchTextBoxReactiveness(bool showResultsWithDelay)
Expand Down Expand Up @@ -785,6 +795,7 @@ private void OnVisibilityChanged(object sender, DependencyPropertyChangedEventAr
{
if (Visibility == Visibility.Visible)
{
PlayAudibleFeedback(true);
_deletePressed = false;
if (_firstDeleteTimer != null)
{
Expand Down Expand Up @@ -815,13 +826,50 @@ private void OnVisibilityChanged(object sender, DependencyPropertyChangedEventAr
}
else
{
PlayAudibleFeedback(false);
if (_firstDeleteTimer != null)
{
_firstDeleteTimer.Stop();
}
}
}

private void PlayAudibleFeedback(bool isOpening)
{
if (!_loadedAtLeastOnce || !_settings.EnableAudibleFeedback)
{
return;
}

bool shouldPlay = isOpening ? _settings.EnableOpeningSound : _settings.EnableClosingSound;
if (!shouldPlay)
{
return;
}

try
{
string fileName = isOpening ? "open.wav" : "close.wav";
string soundPath = Path.Combine(AppContext.BaseDirectory, "Sounds", fileName);

Log.Info($"Attempting to play sound: {soundPath}, Exists: {File.Exists(soundPath)}", GetType());

if (File.Exists(soundPath))
{
PlaySound(soundPath, IntPtr.Zero, SndFilename | SndAsync);
Log.Info($"Playing sound: {soundPath}", GetType());
}
else
{
Log.Info($"Sound file not found: {soundPath}", GetType());
}
}
catch (Exception ex)
{
Log.Exception("Failed to play audible feedback", ex, GetType());
}
}

private void SearchBox_UpdateFlowDirection()
{
SearchBox.QueryTextBox.FlowDirection = MainViewModel.GetLanguageFlowDirection();
Expand Down
8 changes: 8 additions & 0 deletions src/modules/launcher/PowerLauncher/PowerLauncher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@
<ItemGroup>
<Resource Include="Assets\PowerLauncher\RunResource.ico" />
</ItemGroup>
<ItemGroup>
<None Include="Sounds\open.wav">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Sounds\close.wav">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
Expand Down
15 changes: 15 additions & 0 deletions src/modules/launcher/PowerLauncher/SettingsReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,21 @@ public void ReadSettings()
_settings.TitleFontSize = overloadSettings.Properties.TitleFontSize;
}

if (_settings.EnableAudibleFeedback != overloadSettings.Properties.EnableAudibleFeedback)
{
_settings.EnableAudibleFeedback = overloadSettings.Properties.EnableAudibleFeedback;
}

if (_settings.EnableOpeningSound != overloadSettings.Properties.EnableOpeningSound)
{
_settings.EnableOpeningSound = overloadSettings.Properties.EnableOpeningSound;
}

if (_settings.EnableClosingSound != overloadSettings.Properties.EnableClosingSound)
{
_settings.EnableClosingSound = overloadSettings.Properties.EnableClosingSound;
}

retry = false;
}

Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ public int ActivateTimes

public bool RememberLastLaunchLocation { get; set; }

public bool EnableAudibleFeedback { get; set; }

public bool EnableOpeningSound { get; set; }

public bool EnableClosingSound { get; set; }

public enum ShowPluginsOverviewMode
{
All,
Expand Down
12 changes: 12 additions & 0 deletions src/settings-ui/Settings.UI.Library/PowerLauncherProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ public class PowerLauncherProperties
[JsonPropertyName("hotkey_changed")]
public bool HotkeyChanged { get; set; } = false;

[JsonPropertyName("enable_audible_feedback")]
public bool EnableAudibleFeedback { get; set; }

[JsonPropertyName("enable_opening_sound")]
public bool EnableOpeningSound { get; set; }

[JsonPropertyName("enable_closing_sound")]
public bool EnableClosingSound { get; set; }

[CmdConfigureIgnoreAttribute]
public HotkeySettings DefaultOpenPowerLauncher => new HotkeySettings(false, false, true, false, 32);

Expand Down Expand Up @@ -131,6 +140,9 @@ public PowerLauncherProperties()
UsePinyin = false;
ShowPluginsOverview = 0;
TitleFontSize = 16;
EnableAudibleFeedback = false;
EnableOpeningSound = false;
EnableClosingSound = false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ private void SetSetting(Type moduleSettingsType, string settingName, string newV
[DataRow(typeof(AwakeSettings), nameof(AwakeProperties.Mode), "EXPIRABLE")]
[DataRow(typeof(AwakeSettings), nameof(AwakeProperties.ExpirationDateTime), "March 31, 2020 15:00 +00:00")]
[DataRow(typeof(PowerLauncherSettings), nameof(PowerLauncherProperties.MaximumNumberOfResults), "322")]
[DataRow(typeof(PowerLauncherSettings), nameof(PowerLauncherProperties.EnableAudibleFeedback), "true")]
[DataRow(typeof(PowerLauncherSettings), nameof(PowerLauncherProperties.EnableOpeningSound), "true")]
[DataRow(typeof(PowerLauncherSettings), nameof(PowerLauncherProperties.EnableClosingSound), "false")]

[DataRow(typeof(ColorPickerSettings), nameof(ColorPickerProperties.CopiedColorRepresentation), "RGB")]
public void SetModuleSetting(Type moduleSettingsType, string settingName, string newValueStr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ public void OriginalFilesModificationTest(string version, string fileName)
Assert.AreEqual(originalSettings.Properties.UsePinyin, viewModel.UsePinyin);
Assert.AreEqual(originalSettings.Properties.ShowPluginsOverview, viewModel.ShowPluginsOverviewIndex);
Assert.AreEqual(originalSettings.Properties.TitleFontSize, viewModel.TitleFontSize);

Assert.AreEqual(originalSettings.Properties.EnableAudibleFeedback, viewModel.EnableAudibleFeedback);
Assert.AreEqual(originalSettings.Properties.EnableOpeningSound, viewModel.EnableOpeningSound);
Assert.AreEqual(originalSettings.Properties.EnableClosingSound, viewModel.EnableClosingSound);

// Verify that the stub file was used
var expectedCallCount = 2; // once via the view model, and once by the test (GetSettings<T>)
BackCompatTestProperties.VerifyGeneralSettingsIOProviderWasRead(mockGeneralIOProvider, expectedCallCount);
Expand Down Expand Up @@ -205,5 +208,19 @@ public void OverrideShouldUpdateOverrides()
Assert.IsTrue(mockSettings.Properties.OverrideWinkeyR);
Assert.IsFalse(mockSettings.Properties.OverrideWinkeyS);
}

[TestMethod]
public void SoundSettingsShouldUpdateSettings()
{
viewModel.EnableAudibleFeedback = true;
viewModel.EnableOpeningSound = true;
viewModel.EnableClosingSound = false;

Assert.AreEqual(3, sendCallbackMock.TimesSent);

Assert.IsTrue(mockSettings.Properties.EnableAudibleFeedback);
Assert.IsTrue(mockSettings.Properties.EnableOpeningSound);
Assert.IsFalse(mockSettings.Properties.EnableClosingSound);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,26 @@
HeaderIcon="{ui:FontIcon Glyph=&#xE98A;}">
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.UsePinyin, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
<tkcontrols:SettingsExpander
Name="PowerLauncherAudioFeedback"
x:Uid="PowerLauncher_AudioFeedback"
HeaderIcon="{ui:FontIcon Glyph=&#xE7F3;}"
IsExpanded="False">

<ToggleSwitch IsOn="{x:Bind ViewModel.EnableAudibleFeedback, Mode=TwoWay}" />

<tkcontrols:SettingsExpander.Items>
<!-- Opening Sound Toggle -->
<tkcontrols:SettingsCard x:Uid="PowerLauncher_OpeningSoundToggle" IsEnabled="{x:Bind ViewModel.EnableAudibleFeedback, Mode=OneWay}">
<ToggleSwitch IsOn="{x:Bind ViewModel.EnableOpeningSound, Mode=TwoWay}" />
</tkcontrols:SettingsCard>

<!-- Closing Sound Toggle -->
<tkcontrols:SettingsCard x:Uid="PowerLauncher_ClosingSoundToggle" IsEnabled="{x:Bind ViewModel.EnableAudibleFeedback, Mode=OneWay}">
<ToggleSwitch IsOn="{x:Bind ViewModel.EnableClosingSound, Mode=TwoWay}" />
</tkcontrols:SettingsCard>
</tkcontrols:SettingsExpander.Items>
</tkcontrols:SettingsExpander>

<tkcontrols:SettingsCard
Name="PowerLauncherGenerateThumbnailsFromFiles"
Expand Down
12 changes: 12 additions & 0 deletions src/settings-ui/Settings.UI/Strings/en-us/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,18 @@ opera.exe</value>
<data name="PowerLauncher_TabSelectsContextButtons.Description" xml:space="preserve">
<value>Pressing tab will first select through the available context buttons of the current selection before moving onto the next result</value>
</data>
<data name="PowerLauncher_AudioFeedback.Header" xml:space="preserve">
<value>Enable audible feedback</value>
</data>
<data name="PowerLauncher_AudioFeedback.Description" xml:space="preserve">
<value>Play a sound when PowerToys Run opens and closes</value>
</data>
<data name="PowerLauncher_OpeningSoundToggle.Header" xml:space="preserve">
<value>Opening sound</value>
</data>
<data name="PowerLauncher_ClosingSoundToggle.Header" xml:space="preserve">
<value>Closing sound</value>
</data>
<data name="PowerLauncher_GenerateThumbnailsFromFiles.Header" xml:space="preserve">
<value>Generate thumbnails from files</value>
</data>
Expand Down
39 changes: 39 additions & 0 deletions src/settings-ui/Settings.UI/ViewModels/PowerLauncherViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,45 @@ public int TitleFontSize
}
}

public bool EnableAudibleFeedback
{
get => settings.Properties.EnableAudibleFeedback;
set
{
if (settings.Properties.EnableAudibleFeedback != value)
{
settings.Properties.EnableAudibleFeedback = value;
UpdateSettings();
}
}
}

public bool EnableOpeningSound
{
get => settings.Properties.EnableOpeningSound;
set
{
if (settings.Properties.EnableOpeningSound != value)
{
settings.Properties.EnableOpeningSound = value;
UpdateSettings();
}
}
}

public bool EnableClosingSound
{
get => settings.Properties.EnableClosingSound;
set
{
if (settings.Properties.EnableClosingSound != value)
{
settings.Properties.EnableClosingSound = value;
UpdateSettings();
}
}
}

private ObservableCollection<PowerLauncherPluginViewModel> _plugins;

public ObservableCollection<PowerLauncherPluginViewModel> Plugins
Expand Down