Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workspaces] Fix snapshotting Steam #34627

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 43 additions & 3 deletions src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <workspaces-common/WindowFilter.h>

#include <WorkspacesLib/AppUtils.h>
#include <TlHelp32.h>

namespace SnapshotUtils
{
Expand Down Expand Up @@ -168,6 +169,28 @@ namespace SnapshotUtils
return false;
}

DWORD GetParentPid(DWORD pid)
{
DWORD res = 0;
HANDLE h = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe = { 0 };
pe.dwSize = sizeof(PROCESSENTRY32);

if (Process32First(h, &pe))
{
do
{
if (pe.th32ProcessID == pid)
{
res = pe.th32ParentProcessID;
}
} while (Process32Next(h, &pe));
}

CloseHandle(h);
return res;
}

std::vector<WorkspacesData::WorkspacesProject::Application> GetApps(const std::function<unsigned int(HWND)> getMonitorNumberFromWindowHandle)
{
std::vector<WorkspacesData::WorkspacesProject::Application> apps{};
Expand Down Expand Up @@ -245,14 +268,31 @@ namespace SnapshotUtils
auto data = Utils::Apps::GetApp(processPath, installedApps);
if (!data.has_value() || data->name.empty())
{
Logger::debug(L"Installed app not found: {}, {}", title, processPath);
continue;
Logger::info(L"Installed app not found: {}, try parent process", processPath);

// try with parent process (fix for Steam)
auto parentPid = GetParentPid(pid);
auto parentProcessPath = get_process_path(parentPid);
if (!parentProcessPath.empty())
{
data = Utils::Apps::GetApp(parentProcessPath, installedApps);
if (!data.has_value() || data->name.empty())
{
Logger::info(L"Installed parent app not found: {}", processPath);
continue;
}
}
else
{
Logger::info(L"Parent process path not found");
continue;
}
}

WorkspacesData::WorkspacesProject::Application app{
.name = data.value().name,
.title = title,
.path = processPath,
.path = data.value().installPath,
.packageFullName = data.value().packageFullName,
.appUserModelId = data.value().appUserModelId,
.commandLineArgs = L"", // GetCommandLineArgs(pid, wbemHelper),
Expand Down
Loading