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
This commit is contained in:
dlprows 2023-09-24 15:34:17 -06:00
parent bbad79b4f3
commit 13fdfde3e5

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);