diff --git a/GlosSITarget/AppLauncher.cpp b/GlosSITarget/AppLauncher.cpp index 7ecb695..71e10a2 100644 --- a/GlosSITarget/AppLauncher.cpp +++ b/GlosSITarget/AppLauncher.cpp @@ -106,6 +106,7 @@ void AppLauncher::update() } } if (Settings::launch.waitForChildProcs) { + std::erase_if(pids_, [](auto pid) { if (pid == 0) { return true; @@ -115,9 +116,25 @@ void AppLauncher::update() spdlog::trace(L"Child process \"{}\" with PID \"{}\" died", glossi_util::GetProcName(pid), pid); return !running; }); - if (Settings::launch.closeOnExit && pids_.empty() && Settings::launch.launch) { - spdlog::info("Configured to close on all children exit. Shutting down..."); - shutdown_(); + + auto filtered_pids = pids_ | std::ranges::views::filter([](DWORD pid) { + return std::ranges::find(EGS_LAUNCHER_PROCNAMES_, glossi_util::GetProcName(pid)) == EGS_LAUNCHER_PROCNAMES_.end(); + }); + if (was_egs_launch_ && !filtered_pids.empty()) { + egs_has_launched_game_ = true; + } + if (Settings::launch.closeOnExit && Settings::launch.launch) { + if (was_egs_launch_) { + if (egs_has_launched_game_ && filtered_pids.empty()) { + spdlog::info("Configured to close on all children exit. Shutting down after game launched via EGS quit..."); + shutdown_(); + } + } else { + if (pids_.empty()) { + spdlog::info("Configured to close on all children exit. Shutting down..."); + shutdown_(); + } + } } } getProcessHwnds(); @@ -346,6 +363,9 @@ void AppLauncher::launchURL(const std::wstring& url, const std::wstring& args, c } CoUninitialize(); + if (url.find(L"epicgames.launcher") != std::wstring::npos) { + was_egs_launch_ = true; + } if (execute_info.hProcess != nullptr) { if (const auto pid = GetProcessId(execute_info.hProcess); pid > 0) { pid_mutex_.lock(); @@ -356,8 +376,7 @@ void AppLauncher::launchURL(const std::wstring& url, const std::wstring& args, c } } - if (url.find(L"epicgames.launcher") != std::wstring::npos) { - was_egs_launch_ = true; + if (was_egs_launch_) { spdlog::debug("Epic Games launch; Couldn't find egs launcher PID"); pid_mutex_.lock(); diff --git a/GlosSITarget/AppLauncher.h b/GlosSITarget/AppLauncher.h index 4b1472f..84563b9 100644 --- a/GlosSITarget/AppLauncher.h +++ b/GlosSITarget/AppLauncher.h @@ -22,6 +22,7 @@ limitations under the License. #endif #include #include +#include #include #include #include @@ -49,8 +50,14 @@ class AppLauncher { void getProcessHwnds(); std::vector& process_hwnds_; + static inline const std::array EGS_LAUNCHER_PROCNAMES_{ + L"EpicGamesLauncher.exe", + L"EpicWebHelper.exe", + }; + bool was_egs_launch_ = false; + bool egs_has_launched_game_ = false; bool findEgsPid();