Skip to content

Commit

Permalink
Catch errors per device and suppress them after the first error message.
Browse files Browse the repository at this point in the history
  • Loading branch information
hultqvist committed Oct 16, 2023
1 parent e4dad17 commit e528fec
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion FixedMicrophoneLevel/FixedMicrophoneLevel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="AudioSwitcher.AudioApi.CoreAudio">
<Version>3.0.0.1</Version>
<Version>3.0.3</Version>
</PackageReference>
<PackageReference Include="System.Text.Json">
<Version>5.0.2</Version>
Expand Down
33 changes: 29 additions & 4 deletions FixedMicrophoneLevel/Microphone/LevelWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,41 @@ public static void UpdateLevel(bool reportFix)
}
foreach (var dev in audio.GetDevices())
{
if (dev.State != AudioSwitcher.AudioApi.DeviceState.Active)
continue;
try
{
if (dev.State != AudioSwitcher.AudioApi.DeviceState.Active)
continue;

if ((dev.DeviceType & AudioSwitcher.AudioApi.DeviceType.Capture) != 0)
if ((dev.DeviceType & AudioSwitcher.AudioApi.DeviceType.Capture) != 0)
{
UpdateLevel(dev, reportFix);
}
}
catch (Exception ex)
{
UpdateLevel(dev, reportFix);
ShowError(dev, ex);
}
}
}

static List<Guid> supressError = new List<Guid>();

static void ShowError(CoreAudioDevice dev, Exception ex)
{
if (supressError.Contains(dev.Id))
return;
supressError.Add(dev.Id);

if (ex is AggregateException ae && ae.InnerException != null)
{
ShowError(dev, ae.InnerException);
}
else
{
NotifyIconContext.Error(6000, dev.FullName + ":\n" + ex.GetType().Name, ex.Message);
}
}

static void UpdateLevel(CoreAudioDevice dev, bool reportFix)
{
var target = ConfigManager.Target;
Expand Down

0 comments on commit e528fec

Please sign in to comment.