diff --git a/SoundSwitch/Framework/Audio/Microphone/MicrophoneMuteToggler.cs b/SoundSwitch/Framework/Audio/Microphone/MicrophoneMuteToggler.cs index 4a3b114bc5..8d72cd904f 100644 --- a/SoundSwitch/Framework/Audio/Microphone/MicrophoneMuteToggler.cs +++ b/SoundSwitch/Framework/Audio/Microphone/MicrophoneMuteToggler.cs @@ -17,25 +17,29 @@ public MicrophoneMuteToggler(AudioSwitcher switcher) /// /// Toggle mute state for the default microphone /// - /// - public void ToggleDefaultMute() + public bool ToggleDefaultMute() { var microphone = _switcher.GetDefaultMmDevice(EDataFlow.eCapture, ERole.eCommunications); if (microphone == null) { Log.Information("Couldn't find a default microphone to toggle mute"); - return; + return false; } - try + return _switcher.InteractWithMmDevice(microphone, device => { - microphone.AudioEndpointVolume.Mute = !microphone.AudioEndpointVolume.Mute; - } - catch (Exception e) - { - Log.Error("Couldn't toggle mute on {device}:\n{exception}", microphone.FriendlyName, e); - } - + try + { + device.AudioEndpointVolume.Mute = !microphone.AudioEndpointVolume.Mute; + return true; + } + catch (Exception e) + { + Log.Error("Couldn't toggle mute on {device}:\n{exception}", microphone.FriendlyName, e); + } + + return false; + }); } } } \ No newline at end of file