From dc9af4bc30feb7e7084d764246917b417019d95d Mon Sep 17 00:00:00 2001 From: seraphima Date: Wed, 26 Jun 2024 17:40:57 +0200 Subject: [PATCH] update packaged apps path --- .../Projects/ProjectsLauncher/AppLauncher.cpp | 27 ++++++++++++++----- .../Projects/ProjectsLauncher/AppLauncher.h | 2 +- .../Projects/ProjectsLauncher/main.cpp | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/modules/Projects/ProjectsLauncher/AppLauncher.cpp b/src/modules/Projects/ProjectsLauncher/AppLauncher.cpp index 64404281df..be36d69641 100644 --- a/src/modules/Projects/ProjectsLauncher/AppLauncher.cpp +++ b/src/modules/Projects/ProjectsLauncher/AppLauncher.cpp @@ -215,11 +215,8 @@ bool LaunchPackagedApp(const std::wstring& packageFullName) } bool Launch(const Project::Application& app) -{ - // TODO: verify app path is up to date. - // Packaged apps have version in the path, it will be outdated after update. - - bool launched; +{ + bool launched { false }; if (!app.packageFullName.empty() && app.commandLineArgs.empty()) { Logger::trace(L"Launching packaged without command line args {}", app.name); @@ -257,7 +254,7 @@ bool Launch(const Project::Application& app) return launched; } -void Launch(const Project& project) +Project Launch(Project project) { // Get the set of windows before launching the app std::vector windowsBefore = WindowEnumerator::Enumerate(WindowFilter::Filter); @@ -265,8 +262,22 @@ void Launch(const Project& project) auto apps = Utils::Apps::GetAppsList(); auto monitors = MonitorUtils::IdentifyMonitors(); - for (const auto& app : project.apps) + for (auto& app : project.apps) { + // Packaged apps have version in the path, it will be outdated after update. + // We need make sure the current package is up to date. + if (!app.packageFullName.empty()) + { + auto installedApp = std::find_if(apps.begin(), apps.end(), [&](const Utils::Apps::AppData& val) { return val.name == app.name; }); + if (installedApp != apps.end() && app.packageFullName != installedApp->packageFullName) + { + std::wstring exeFileName = app.path.substr(app.path.find_last_of(L"\\") + 1); + app.packageFullName = installedApp->packageFullName; + app.path = installedApp->installPath + L"\\" + exeFileName; + Logger::trace(L"Updated package full name for {}: {}", app.name, app.packageFullName); + } + } + if (Launch(app)) { launchedWindows.push_back({ app, nullptr }); @@ -378,4 +389,6 @@ void Launch(const Project& project) Logger::error(L"Failed placing {}", app.name); } } + + return project; } diff --git a/src/modules/Projects/ProjectsLauncher/AppLauncher.h b/src/modules/Projects/ProjectsLauncher/AppLauncher.h index 8bf78cf5cc..f99841653f 100644 --- a/src/modules/Projects/ProjectsLauncher/AppLauncher.h +++ b/src/modules/Projects/ProjectsLauncher/AppLauncher.h @@ -3,4 +3,4 @@ #include bool Launch(const Project::Application& app); -void Launch(const Project& project); \ No newline at end of file +Project Launch(Project project); \ No newline at end of file diff --git a/src/modules/Projects/ProjectsLauncher/main.cpp b/src/modules/Projects/ProjectsLauncher/main.cpp index 2c6bed9dd9..570f987ff1 100644 --- a/src/modules/Projects/ProjectsLauncher/main.cpp +++ b/src/modules/Projects/ProjectsLauncher/main.cpp @@ -76,7 +76,7 @@ int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cm Logger::info(L"Launch Project {} : {}", projectToLaunch.name, projectToLaunch.id); // launch apps - Launch(projectToLaunch); + projectToLaunch = Launch(projectToLaunch); // update last-launched time time_t launchedTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());