Compare commits

..

No commits in common. "609a7bdb655c7cabb53ad44e8371eb13bde2f630" and "bbad79b4f38582a95521d78894fb69bf11c81429" have entirely different histories.

View File

@ -36,7 +36,6 @@ public class AudioHelper
manager.GetSessionEnumerator(out var sessionEnumerator); manager.GetSessionEnumerator(out var sessionEnumerator);
var results = new ActiveAudioSessionWrapper(); var results = new ActiveAudioSessionWrapper();
var currentIndex = int.MaxValue;
sessionEnumerator.GetCount(out var count); sessionEnumerator.GetCount(out var count);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
@ -46,33 +45,23 @@ public class AudioHelper
session.GetProcessId(out var sessionProcessId); session.GetProcessId(out var sessionProcessId);
var audioProcess = Process.GetProcessById(sessionProcessId); var audioProcess = Process.GetProcessById(sessionProcessId);
var index = processes.FindIndex(x => x.Id == sessionProcessId || x.ProcessName == audioProcess?.ProcessName); if (processes.Any(x => x.Id == sessionProcessId || x.ProcessName == audioProcess?.ProcessName))
if (index > -1)
{ {
//processes will be ordered from best to worst (starts with the app, goes to parent) try
//so we want the display name and executable path to come from the process that is closest to the front of the list
//but we want all matching sessions so things like discord work right
if (index < currentIndex)
{ {
try var displayName = audioProcess.MainModule.FileVersionInfo.FileDescription;
if (string.IsNullOrEmpty(displayName))
{ {
var displayName = audioProcess.MainModule.FileVersionInfo.FileDescription; displayName = audioProcess.ProcessName;
if (string.IsNullOrEmpty(displayName))
{
displayName = audioProcess.ProcessName;
}
results.DisplayName = displayName;
} }
catch results.DisplayName = displayName;
{
results.DisplayName = audioProcess.ProcessName;
}
results.ExecutablePath = audioProcess.MainModule.FileName;
currentIndex = index;
} }
catch
{
results.DisplayName ??= audioProcess.ProcessName;
}
results.ExecutablePath ??= audioProcess.MainModule.FileName;
//some apps like discord have multiple volume processes. //some apps like discord have multiple volume processes.
results.AddSession(session); results.AddSession(session);
@ -154,15 +143,14 @@ public class AudioHelper
//Additionally, I group all audio processes that match instead of just the most specific, or the first, etc. Because Discord uses two processes, one for voice chat, and one for discord sounds. //Additionally, I group all audio processes that match instead of just the most specific, or the first, etc. Because Discord uses two processes, one for voice chat, and one for discord sounds.
// //
//Steam and Discord are both very common, and end up butting heads in the algorithm. //Steam and Discord are both very common, and end up butting heads in the algorithm.
//I want to avoid special cases, but since steam and discord are both so common, i'm making an exception. //And I'm not overly fond of programming in special cases
var parentProcess = ParentProcessUtilities.GetParentProcess(pid); //so for the time being, the only down side i've found for including the parent process is that when you launch a game from steam and change the volume, you also change steam's volume. but that really only impacts videos on steam store pages
if (parentProcess != null //The icon is also often steam's icon instead of the games'.
&& parentProcess.ProcessName != "explorer" //But i'm striving for functional before perfection.
&& parentProcess.ProcessName != "svchost" var blah = ParentProcessUtilities.GetParentProcess(pid);
&& (parentProcess.ProcessName == "steam" && processes.Any(x => x.ProcessName == "steamwebhelper")) //only include steam if the parent process is the steamwebhelper if (blah != null && blah.ProcessName != "explorer" && blah.ProcessName != "svchost")
)
{ {
processes.Add(parentProcess); processes.Add(blah);
} }
} }
catch catch