From de27a6cceebcacfb7b9c4e485e4bf222feb1d947 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Sun, 28 Feb 2021 13:55:47 +0100 Subject: [PATCH] Implemented toggle and inverted settings for muted actions --- .../DeviceGetMutedActionSettingsView.xaml | 5 +++- .../OSD/OSDManager.cs | 14 ++++++++-- .../DeviceSetMutedActionSettingsView.xaml | 14 ++++++++-- .../DeviceSetMutedActionSettingsViewModel.cs | 26 ++++++++++++++++--- .../Strings.Designer.cs | 4 +-- .../MassiveKnob.Plugin.CoreAudio/Strings.resx | 4 +-- 6 files changed, 55 insertions(+), 12 deletions(-) diff --git a/Windows/MassiveKnob.Plugin.CoreAudio/GetMuted/DeviceGetMutedActionSettingsView.xaml b/Windows/MassiveKnob.Plugin.CoreAudio/GetMuted/DeviceGetMutedActionSettingsView.xaml index 85c6576..09b2175 100644 --- a/Windows/MassiveKnob.Plugin.CoreAudio/GetMuted/DeviceGetMutedActionSettingsView.xaml +++ b/Windows/MassiveKnob.Plugin.CoreAudio/GetMuted/DeviceGetMutedActionSettingsView.xaml @@ -5,12 +5,15 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:getMuted="clr-namespace:MassiveKnob.Plugin.CoreAudio.GetMuted" xmlns:base="clr-namespace:MassiveKnob.Plugin.CoreAudio.Base" + xmlns:coreAudio="clr-namespace:MassiveKnob.Plugin.CoreAudio" mc:Ignorable="d" d:DesignHeight="200" d:DesignWidth="800" d:DataContext="{d:DesignInstance getMuted:DeviceGetMutedActionSettingsViewModel}"> - + + + diff --git a/Windows/MassiveKnob.Plugin.CoreAudio/OSD/OSDManager.cs b/Windows/MassiveKnob.Plugin.CoreAudio/OSD/OSDManager.cs index eca825f..77ffd61 100644 --- a/Windows/MassiveKnob.Plugin.CoreAudio/OSD/OSDManager.cs +++ b/Windows/MassiveKnob.Plugin.CoreAudio/OSD/OSDManager.cs @@ -1,4 +1,5 @@ -using System.Threading; +using System; +using System.Threading; using System.Windows; using AudioSwitcher.AudioApi; @@ -20,6 +21,7 @@ namespace MassiveKnob.Plugin.CoreAudio.OSD { windowViewModel = new OSDWindowViewModel(); window = new OSDWindow(windowViewModel); + window.Closed += WindowOnClosed; hideTimer = new Timer(state => { @@ -34,9 +36,17 @@ namespace MassiveKnob.Plugin.CoreAudio.OSD }); } + + private static void WindowOnClosed(object sender, EventArgs e) + { + hideTimer?.Dispose(); + hideTimer = null; + } + + private static void Hide() { - Application.Current.Dispatcher.Invoke(() => + Application.Current?.Dispatcher.Invoke(() => { window?.Close(); window = null; diff --git a/Windows/MassiveKnob.Plugin.CoreAudio/SetMuted/DeviceSetMutedActionSettingsView.xaml b/Windows/MassiveKnob.Plugin.CoreAudio/SetMuted/DeviceSetMutedActionSettingsView.xaml index 3a73fce..d189e7b 100644 --- a/Windows/MassiveKnob.Plugin.CoreAudio/SetMuted/DeviceSetMutedActionSettingsView.xaml +++ b/Windows/MassiveKnob.Plugin.CoreAudio/SetMuted/DeviceSetMutedActionSettingsView.xaml @@ -5,13 +5,23 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:setMuted="clr-namespace:MassiveKnob.Plugin.CoreAudio.SetMuted" xmlns:base="clr-namespace:MassiveKnob.Plugin.CoreAudio.Base" + xmlns:coreAudio="clr-namespace:MassiveKnob.Plugin.CoreAudio" mc:Ignorable="d" d:DesignHeight="200" d:DesignWidth="800" d:DataContext="{d:DesignInstance setMuted:DeviceSetMutedActionSettingsViewModel}"> - - + + + + + + + + + + + diff --git a/Windows/MassiveKnob.Plugin.CoreAudio/SetMuted/DeviceSetMutedActionSettingsViewModel.cs b/Windows/MassiveKnob.Plugin.CoreAudio/SetMuted/DeviceSetMutedActionSettingsViewModel.cs index 7045a8c..70f214f 100644 --- a/Windows/MassiveKnob.Plugin.CoreAudio/SetMuted/DeviceSetMutedActionSettingsViewModel.cs +++ b/Windows/MassiveKnob.Plugin.CoreAudio/SetMuted/DeviceSetMutedActionSettingsViewModel.cs @@ -5,15 +5,35 @@ namespace MassiveKnob.Plugin.CoreAudio.SetMuted public class DeviceSetMutedActionSettingsViewModel : BaseDeviceSettingsViewModel { // ReSharper disable UnusedMember.Global - used by WPF Binding - public bool Toggle + public bool ToggleTrue { get => Settings.Toggle; set { - if (value == Settings.Toggle) + if (!value) + return; + + if (Settings.Toggle) return; - Settings.Toggle = value; + Settings.Toggle = true; + OnPropertyChanged(); + } + } + + + public bool ToggleFalse + { + get => !Settings.Toggle; + set + { + if (!value) + return; + + if (!Settings.Toggle) + return; + + Settings.Toggle = false; OnPropertyChanged(); } } diff --git a/Windows/MassiveKnob.Plugin.CoreAudio/Strings.Designer.cs b/Windows/MassiveKnob.Plugin.CoreAudio/Strings.Designer.cs index fd60a71..e855eab 100644 --- a/Windows/MassiveKnob.Plugin.CoreAudio/Strings.Designer.cs +++ b/Windows/MassiveKnob.Plugin.CoreAudio/Strings.Designer.cs @@ -178,7 +178,7 @@ namespace MassiveKnob.Plugin.CoreAudio { } /// - /// Looks up a localized string similar to Inverted (muted is off). + /// Looks up a localized string similar to Inverted (off when muted). /// public static string SettingGetMutedInverted { get { @@ -205,7 +205,7 @@ namespace MassiveKnob.Plugin.CoreAudio { } /// - /// Looks up a localized string similar to Inverted (off is muted). + /// Looks up a localized string similar to Inverted (muted when off). /// public static string SettingSetMutedSetInverted { get { diff --git a/Windows/MassiveKnob.Plugin.CoreAudio/Strings.resx b/Windows/MassiveKnob.Plugin.CoreAudio/Strings.resx index f49a4c9..1339126 100644 --- a/Windows/MassiveKnob.Plugin.CoreAudio/Strings.resx +++ b/Windows/MassiveKnob.Plugin.CoreAudio/Strings.resx @@ -157,7 +157,7 @@ Mute / unmute - Inverted (muted is off) + Inverted (off when muted) Show On-Screen Display @@ -166,7 +166,7 @@ Playback device - Inverted (off is muted) + Inverted (muted when off) Set mute depending on value (eg. switch)