From 782a2e1b1edda5efafc31b82d9230601ee95fad9 Mon Sep 17 00:00:00 2001 From: seraphima Date: Wed, 5 Jun 2024 16:28:00 +0200 Subject: [PATCH] check single-instance apps running --- .../Projects/ProjectsLauncher/AppLauncher.cpp | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/modules/Projects/ProjectsLauncher/AppLauncher.cpp b/src/modules/Projects/ProjectsLauncher/AppLauncher.cpp index 6450866ee5..e30982a56a 100644 --- a/src/modules/Projects/ProjectsLauncher/AppLauncher.cpp +++ b/src/modules/Projects/ProjectsLauncher/AppLauncher.cpp @@ -6,6 +6,7 @@ #include +#include "../projects-common/AppUtils.h" #include "../projects-common/MonitorEnumerator.h" #include "../projects-common/WindowEnumerator.h" #include "../projects-common/WindowFilter.h" @@ -280,10 +281,33 @@ bool Launch(const Project::Application& app) } } + // The app wasn't launched, check if it's already launched for single-instance apps if (launchedWindows.empty()) { - std::wcout << L"Failed to launch " << app.name << std::endl; - return false; + std::wcout << L"Failed to launch " << app.name << L", checking if it's launched already." << std::endl; + + auto apps = Utils::Apps::GetAppsList(); + auto windows = WindowEnumerator::Enumerate(WindowFilter::Filter); + for (HWND window : windows) + { + std::wstring processPath = Common::Utils::ProcessPath::get_process_path_waiting_uwp(window); + auto data = Utils::Apps::GetApp(processPath, apps); + if (!data.has_value()) + { + continue; + } + + if (data.value().name == app.name) + { + launchedWindows.push_back(window); + } + } + } + + // The single-instance app not found + if (launchedWindows.empty()) + { + return false; } // Place the window