Fix up the title to be an iterated ID rather than PID

This commit is contained in:
2025-06-26 22:18:56 +02:00
parent e1e223a097
commit 5373ba8cfe

View File

@@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
namespace EveOPreview.Services.Implementation
{
@@ -91,8 +92,16 @@ namespace EveOPreview.Services.Implementation
continue; // No need to monitor non-visual processes
}
// Append PID to the window title to make it unique
string mainWindowTitle = $"{process.MainWindowTitle} (PID: {process.Id})";
// Get all processes with same name and sort by PID
var sameNameProcesses = Process.GetProcessesByName(processName)
.Where(p => p.MainWindowHandle != IntPtr.Zero)
.OrderBy(p => p.Id)
.ToList();
// Find index of current process in sorted list
int index = sameNameProcesses.FindIndex(p => p.Id == process.Id);
string mainWindowTitle = $"{process.MainWindowTitle} ({index + 1})";
this._processCache.TryGetValue(mainWindowHandle, out string cachedTitle);
if (cachedTitle == null)
@@ -109,10 +118,10 @@ namespace EveOPreview.Services.Implementation
this._processCache[mainWindowHandle] = mainWindowTitle;
updatedProcesses.Add(new ProcessInfo(mainWindowHandle, mainWindowTitle));
}
}
knownProcesses.Remove(mainWindowHandle);
}
}
foreach (IntPtr index in knownProcesses)
{