From 6575197446d9a8bb275377c599579b6b7671a7fa Mon Sep 17 00:00:00 2001 From: Stas Geft Date: Mon, 24 Oct 2022 17:31:20 +0300 Subject: [PATCH] Optional fix to prevent resetting an output device volume balance --- Volumey/DataProvider/AppSettings.cs | 3 +++ Volumey/Model/MasterSessionModel.cs | 10 +++++++++- Volumey/Resources/Resources.en.resx | 3 +++ Volumey/Resources/Resources.resx | 3 +++ Volumey/Resources/Resources.ru.resx | 3 +++ .../SettingsPage/DeviceVolumeHotkeysPage.xaml | 4 ++++ .../Settings/DeviceVolumeHotkeysViewModel.cs | 18 ++++++++++++++++++ 7 files changed, 43 insertions(+), 1 deletion(-) diff --git a/Volumey/DataProvider/AppSettings.cs b/Volumey/DataProvider/AppSettings.cs index 84b8ad9..b15b2a8 100644 --- a/Volumey/DataProvider/AppSettings.cs +++ b/Volumey/DataProvider/AppSettings.cs @@ -369,6 +369,9 @@ internal HotKey ForegroundVolumeDown } } + [OptionalField] + public bool PreventResettingVolumeBalance; + [OptionalField] public List RegisteredSystemHotkeys = new List(); diff --git a/Volumey/Model/MasterSessionModel.cs b/Volumey/Model/MasterSessionModel.cs index d8b9182..a76200e 100644 --- a/Volumey/Model/MasterSessionModel.cs +++ b/Volumey/Model/MasterSessionModel.cs @@ -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); } } diff --git a/Volumey/Resources/Resources.en.resx b/Volumey/Resources/Resources.en.resx index 33caebf..56b1866 100644 --- a/Volumey/Resources/Resources.en.resx +++ b/Volumey/Resources/Resources.en.resx @@ -253,4 +253,7 @@ Screen to display + + Prevent resetting the volume balance by muting the device instead of setting the volume to 0 + \ No newline at end of file diff --git a/Volumey/Resources/Resources.resx b/Volumey/Resources/Resources.resx index 276ca7f..e0ad274 100644 --- a/Volumey/Resources/Resources.resx +++ b/Volumey/Resources/Resources.resx @@ -210,4 +210,7 @@ + + + \ No newline at end of file diff --git a/Volumey/Resources/Resources.ru.resx b/Volumey/Resources/Resources.ru.resx index 37d6be5..a616ea6 100644 --- a/Volumey/Resources/Resources.ru.resx +++ b/Volumey/Resources/Resources.ru.resx @@ -253,4 +253,7 @@ Дисплей для отображения + + Предотвращать сброс баланса звука заглушая устройство вместо установки громкости на 0 + \ No newline at end of file diff --git a/Volumey/View/SettingsPage/DeviceVolumeHotkeysPage.xaml b/Volumey/View/SettingsPage/DeviceVolumeHotkeysPage.xaml index 8a9ff0d..0d37b20 100644 --- a/Volumey/View/SettingsPage/DeviceVolumeHotkeysPage.xaml +++ b/Volumey/View/SettingsPage/DeviceVolumeHotkeysPage.xaml @@ -64,6 +64,10 @@ IsEnabled="{Binding MuteKey, Converter={StaticResource AnyPropertyIsNullToEnabledConverter}}"> + + + + diff --git a/Volumey/ViewModel/Settings/DeviceVolumeHotkeysViewModel.cs b/Volumey/ViewModel/Settings/DeviceVolumeHotkeysViewModel.cs index 86ff791..a5a41e6 100644 --- a/Volumey/ViewModel/Settings/DeviceVolumeHotkeysViewModel.cs +++ b/Volumey/ViewModel/Settings/DeviceVolumeHotkeysViewModel.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.Threading.Tasks; using log4net; using Volumey.Controls; using Volumey.DataProvider; @@ -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 @@ -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