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:
parent
bbad79b4f3
commit
13fdfde3e5
@ -36,6 +36,7 @@ public class AudioHelper
|
||||
manager.GetSessionEnumerator(out var sessionEnumerator);
|
||||
|
||||
var results = new ActiveAudioSessionWrapper();
|
||||
var currentIndex = int.MaxValue;
|
||||
|
||||
sessionEnumerator.GetCount(out var count);
|
||||
for (int i = 0; i < count; i++)
|
||||
@ -45,7 +46,14 @@ public class AudioHelper
|
||||
session.GetProcessId(out var 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);
|
||||
|
||||
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
|
||||
{
|
||||
@ -58,10 +66,13 @@ public class AudioHelper
|
||||
}
|
||||
catch
|
||||
{
|
||||
results.DisplayName ??= audioProcess.ProcessName;
|
||||
results.DisplayName = audioProcess.ProcessName;
|
||||
}
|
||||
|
||||
results.ExecutablePath ??= audioProcess.MainModule.FileName;
|
||||
results.ExecutablePath = audioProcess.MainModule.FileName;
|
||||
|
||||
currentIndex = index;
|
||||
}
|
||||
|
||||
//some apps like discord have multiple volume processes.
|
||||
results.AddSession(session);
|
||||
|
Loading…
Reference in New Issue
Block a user