Skip to content

Commit

Permalink
Optional fix to prevent resetting an output device volume balance
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Stas committed Oct 24, 2022
1 parent 181cae3 commit 6575197
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Volumey/DataProvider/AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,9 @@ internal HotKey ForegroundVolumeDown
}
}

[OptionalField]
public bool PreventResettingVolumeBalance;

[OptionalField]
public List<SystemHotkey> RegisteredSystemHotkeys = new List<SystemHotkey>();

Expand Down
10 changes: 9 additions & 1 deletion Volumey/Model/MasterSessionModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,19 @@ private void OnHotkeyPressed(HotKey hotkey)
{
if(hotkey.Equals(this.volumeUp))
{
if(SettingsProvider.HotkeysSettings.PreventResettingVolumeBalance && this.IsMuted)
this.SetMute(false, notify: false, ref GuidValue.Internal.Empty);
this.SetVolume(this.Volume + HotkeysControl.VolumeStep, notify:true, ref GuidValue.Internal.Empty);
}
else if(hotkey.Equals(this.volumeDown))
{
this.SetVolume(this.Volume - HotkeysControl.VolumeStep, notify: true, ref GuidValue.Internal.Empty);
int newValue = this.Volume - HotkeysControl.VolumeStep;
if(SettingsProvider.HotkeysSettings.PreventResettingVolumeBalance && newValue <= 0)
{
this.SetMute(true, notify: true, ref GuidValue.Internal.Empty);
}
else
this.SetVolume(newValue, notify: true, ref GuidValue.Internal.Empty);
}
}

Expand Down
3 changes: 3 additions & 0 deletions Volumey/Resources/Resources.en.resx
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,7 @@
<data name="Settings_SelectedScreen" xml:space="preserve">
<value>Screen to display</value>
</data>
<data name="Settings_PreventBalanceReset" xml:space="preserve">
<value>Prevent resetting the volume balance by muting the device instead of setting the volume to 0</value>
</data>
</root>
3 changes: 3 additions & 0 deletions Volumey/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,7 @@
<data name="Settings_SelectedScreen" xml:space="preserve">
<value></value>
</data>
<data name="Settings_PreventBalanceReset" xml:space="preserve">
<value></value>
</data>
</root>
3 changes: 3 additions & 0 deletions Volumey/Resources/Resources.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,7 @@
<data name="Settings_SelectedScreen" xml:space="preserve">
<value>Дисплей для отображения</value>
</data>
<data name="Settings_PreventBalanceReset" xml:space="preserve">
<value>Предотвращать сброс баланса звука заглушая устройство вместо установки громкости на 0</value>
</data>
</root>
4 changes: 4 additions & 0 deletions Volumey/View/SettingsPage/DeviceVolumeHotkeysPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
IsEnabled="{Binding MuteKey, Converter={StaticResource AnyPropertyIsNullToEnabledConverter}}">
</ui:ToggleSwitch>
</StackPanel>

<TextBlock Text="{lc:Localization Settings_PreventBalanceReset}"/>
<ui:ToggleSwitch IsOn="{Binding PreventResettingVolumeBalance}"/>

<TextBlock
Text="{Binding ErrorMessage}"
Foreground="Red"/>
Expand Down
18 changes: 18 additions & 0 deletions Volumey/ViewModel/Settings/DeviceVolumeHotkeysViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System.Threading.Tasks;
using log4net;
using Volumey.Controls;
using Volumey.DataProvider;
Expand Down Expand Up @@ -80,6 +81,22 @@ public bool MuteHotkeyRegistered
OnPropertyChanged();
}
}

private bool _preventResettingVolumeBalance;
public bool PreventResettingVolumeBalance
{
get => _preventResettingVolumeBalance;
set
{
_preventResettingVolumeBalance = value;
OnPropertyChanged();
if(SettingsProvider.HotkeysSettings.PreventResettingVolumeBalance != value)
{
SettingsProvider.HotkeysSettings.PreventResettingVolumeBalance = value;
_ = Task.Run(async () => { await SettingsProvider.SaveSettings(); });
}
}
}

private AudioProcessStateNotificationMediator _dMediator;
private AudioProcessStateNotificationMediator DeviceMediator
Expand All @@ -102,6 +119,7 @@ public DeviceVolumeHotkeysViewModel()
ErrorDictionary.LanguageChanged += () => this.SetErrorMessage(this.CurrentErrorType);

var hotkeysSettings = SettingsProvider.HotkeysSettings;
PreventResettingVolumeBalance = hotkeysSettings.PreventResettingVolumeBalance;
var anyHotkeysRegistered = false;

//set volume hotkeys if they are exist in settings
Expand Down

0 comments on commit 6575197

Please sign in to comment.