Skip to content

Commit

Permalink
[Workspaces] implement standalone app handling
Browse files Browse the repository at this point in the history
  • Loading branch information
donlaci committed Sep 18, 2024
1 parent 9bfee34 commit 12c6fd8
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/modules/Workspaces/WorkspacesLauncher/AppLauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ namespace
auto insertionIter = launchedApps.end();
for (auto iter = launchedApps.begin(); iter != launchedApps.end(); ++iter)
{
if (iter->window == nullptr && installedAppData.value().name == iter->application.name)
if (iter->window == nullptr && (installedAppData.value().name == iter->application.name) || (installedAppData.value().installPath == iter->application.path))
{
insertionIter = iter;
}
Expand Down
69 changes: 57 additions & 12 deletions src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ namespace SnapshotUtils
return res;
}

bool IsFileManagerApp(std::wstring processPath)
{
std::wstring appName = std::filesystem::path(processPath).stem();
std::transform(appName.begin(), appName.end(), appName.begin(), towupper);
return ((appName == L"EXPLORER") // windows explorer
|| (appName.starts_with(L"TOTALCMD")) // total commander

Check failure on line 199 in src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.cpp

View workflow job for this annotation

GitHub Actions / Spell checking

`TOTALCMD` is not a recognized word. (unrecognized-spelling)
|| (appName == L"DOPUS") // directory opus

Check failure on line 200 in src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.cpp

View workflow job for this annotation

GitHub Actions / Spell checking

`DOPUS` is not a recognized word. (unrecognized-spelling)
|| (appName == L"Q-DIR") // Q-Dir
|| (appName.starts_with(L"XPLORER2"))); // Xplorer2

Check failure on line 202 in src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.cpp

View workflow job for this annotation

GitHub Actions / Spell checking

`XPLORER` is not a recognized word. (unrecognized-spelling)

Check failure on line 202 in src/modules/Workspaces/WorkspacesSnapshotTool/SnapshotUtils.cpp

View workflow job for this annotation

GitHub Actions / Spell checking

`Xplorer` is not a recognized word. (unrecognized-spelling)
}

std::vector<WorkspacesData::WorkspacesProject::Application> GetApps(const std::function<unsigned int(HWND)> getMonitorNumberFromWindowHandle)
{
std::vector<WorkspacesData::WorkspacesProject::Application> apps{};
Expand Down Expand Up @@ -269,25 +280,59 @@ namespace SnapshotUtils
if (!data.has_value() || data->name.empty())
{
Logger::info(L"Installed app not found: {}, try parent process", processPath);


bool standaloneApp = false;
bool steamLikeApp = false;

// 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;
}

processPath = parentProcessPath;
// check if original process is in the subfolder of the parent process which is a sign of an steam-like app
auto processDir = std::filesystem::path(processPath).parent_path();
auto parentProcessDir = std::filesystem::path(parentProcessPath).parent_path();

if (std::wstring(processDir).starts_with(std::wstring(parentProcessDir)))
{
Logger::info(L"parent process: {}, original process is in the subfolder of the parent process, it is a steam-like app", parentProcessPath);
steamLikeApp = true;
}
else if (IsFileManagerApp(parentProcessPath))
{
Logger::info(L"parent process: {}, The parent process is a known file manager app, it is a standalone app", parentProcessPath);
standaloneApp = true;
}
else
{
Logger::info(L"Parent process path not found");
continue;
Logger::info(L"parent process: {}, The parent process is NOT a known file manager app, it is a steam-like app", parentProcessPath);
steamLikeApp = true;
}

if (standaloneApp)
{
data = Utils::Apps::AppData{
.name = std::filesystem::path(processPath).stem(),
.installPath = processPath,
};
}
else if (steamLikeApp)
{
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;
}

processPath = parentProcessPath;
}
else
{
Logger::info(L"Parent process path not found");
continue;
}
}
}

Expand Down

0 comments on commit 12c6fd8

Please sign in to comment.