Compare commits

...

2 Commits

Author SHA1 Message Date
609a7bdb65 Add a special case to make steam launched games not control steam's sound, because after fixing the process matching to make it pick up the right name and icon consistently, it makes it weirder for steam to have its volume changed unexpectedly 2023-09-24 15:35:07 -06:00
13fdfde3e5 Improve process matching by using the display name and icon of the first match in the process list.
previously it was non-deterministic, so you would sometimes get steam icon with game name, or steam name and icon even though the game was being controlled.
This makes it more consistently the correct icon and name
2023-09-24 15:34:17 -06:00

View File

@ -36,6 +36,7 @@ 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++)
@ -45,23 +46,33 @@ public class AudioHelper
session.GetProcessId(out var sessionProcessId); session.GetProcessId(out var sessionProcessId);
var audioProcess = Process.GetProcessById(sessionProcessId); var audioProcess = Process.GetProcessById(sessionProcessId);
if (processes.Any(x => x.Id == sessionProcessId || x.ProcessName == audioProcess?.ProcessName)) var index = processes.FindIndex(x => x.Id == sessionProcessId || x.ProcessName == audioProcess?.ProcessName);
{
try
{
var displayName = audioProcess.MainModule.FileVersionInfo.FileDescription;
if (string.IsNullOrEmpty(displayName))
{
displayName = audioProcess.ProcessName;
}
results.DisplayName = displayName;
}
catch
{
results.DisplayName ??= audioProcess.ProcessName;
}
results.ExecutablePath ??= audioProcess.MainModule.FileName; if (index > -1)
{
//processes will be ordered from best to worst (starts with the app, goes to parent)
//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))
{
displayName = audioProcess.ProcessName;
}
results.DisplayName = displayName;
}
catch
{
results.DisplayName = audioProcess.ProcessName;
}
results.ExecutablePath = audioProcess.MainModule.FileName;
currentIndex = index;
}
//some apps like discord have multiple volume processes. //some apps like discord have multiple volume processes.
results.AddSession(session); results.AddSession(session);
@ -143,14 +154,15 @@ 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.
//And I'm not overly fond of programming in special cases //I want to avoid special cases, but since steam and discord are both so common, i'm making an exception.
//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 var parentProcess = ParentProcessUtilities.GetParentProcess(pid);
//The icon is also often steam's icon instead of the games'. if (parentProcess != null
//But i'm striving for functional before perfection. && parentProcess.ProcessName != "explorer"
var blah = ParentProcessUtilities.GetParentProcess(pid); && parentProcess.ProcessName != "svchost"
if (blah != null && blah.ProcessName != "explorer" && blah.ProcessName != "svchost") && (parentProcess.ProcessName == "steam" && processes.Any(x => x.ProcessName == "steamwebhelper")) //only include steam if the parent process is the steamwebhelper
)
{ {
processes.Add(blah); processes.Add(parentProcess);
} }
} }
catch catch