Skip to content

Commit 6d63226

Browse files
committed
feat(Mute): Return the state of mute after action
1 parent 4ef87a4 commit 6d63226

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

SoundSwitch/Framework/Audio/Microphone/MicrophoneMuteToggler.cs

+8-6
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,31 @@ public MicrophoneMuteToggler(AudioSwitcher switcher)
1616

1717
/// <summary>
1818
/// Toggle mute state for the default microphone
19+
/// <returns>The current mute state, null if couldn't interact with the microphone</returns>
1920
/// </summary>
20-
public bool ToggleDefaultMute()
21+
public bool? ToggleDefaultMute()
2122
{
2223
var microphone = _switcher.GetDefaultMmDevice(EDataFlow.eCapture, ERole.eCommunications);
2324
if (microphone == null)
2425
{
2526
Log.Information("Couldn't find a default microphone to toggle mute");
26-
return false;
27+
return null;
2728
}
2829

29-
return _switcher.InteractWithMmDevice(microphone, device =>
30+
return _switcher.InteractWithMmDevice<bool?>(microphone, device =>
3031
{
3132
try
3233
{
33-
device.AudioEndpointVolume.Mute = !microphone.AudioEndpointVolume.Mute;
34-
return true;
34+
var newMuteState = !microphone.AudioEndpointVolume.Mute;
35+
device.AudioEndpointVolume.Mute = newMuteState;
36+
return newMuteState;
3537
}
3638
catch (Exception e)
3739
{
3840
Log.Error("Couldn't toggle mute on {device}:\n{exception}", microphone.FriendlyName, e);
3941
}
4042

41-
return false;
43+
return null;
4244
});
4345
}
4446
}

0 commit comments

Comments
 (0)