Skip to content

Commit 0d74009

Browse files
committed
Added a fallback to grab the process name
1 parent ba521f0 commit 0d74009

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Sidekick.Common.Platform/Windows/Processes/ProcessProvider.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,19 @@ public string? ClientLogPath
8989
}
9090
else
9191
{
92-
PreviousFocusedWindow = null;
92+
// Try to get the process name as a fallback
93+
try
94+
{
95+
var hWnd = User32.GetForegroundWindow();
96+
User32.GetWindowThreadProcessId(hWnd, out var processId);
97+
var process = Process.GetProcessById((int)processId);
98+
logger.LogDebug("Fallback to process name: {0}", process.ProcessName);
99+
PreviousFocusedWindow = process.ProcessName;
100+
}
101+
catch (Exception)
102+
{
103+
PreviousFocusedWindow = null;
104+
}
93105
}
94106

95107
return PreviousFocusedWindow;
@@ -102,7 +114,7 @@ public bool IsPathOfExileInFocus
102114
{
103115
var focusedWindow = GetFocusedWindow();
104116

105-
// logger.LogDebug("[ProcessProvider] Current focused window title: {0}", focusedWindow);
117+
logger.LogDebug("[ProcessProvider] Current focused window title: {0}", focusedWindow);
106118
return focusedWindow is PATH_OF_EXILE_TITLE or PATH_OF_EXILE_2_TITLE;
107119
}
108120
}

0 commit comments

Comments
 (0)