fix: Make sure updater properly exists after launching update process

This commit is contained in:
WerWolv
2025-12-29 13:35:44 +01:00
parent 53153ca3e0
commit e28f3b75a4
3 changed files with 43 additions and 1 deletions

View File

@@ -99,6 +99,7 @@ namespace hex {
void startProgram(const std::vector<std::string> &command);
int executeCommand(const std::string &command);
std::optional<std::string> executeCommandWithOutput(const std::string &command);
void executeCommandDetach(const std::string &command);
void openWebpage(std::string url);
extern "C" void registerFont(const char *fontName, const char *fontPath);

View File

@@ -30,10 +30,12 @@
#elif defined(OS_LINUX)
#include <unistd.h>
#include <dlfcn.h>
#include <spawn.h>
#include <hex/helpers/utils_linux.hpp>
#elif defined(OS_MACOS)
#include <unistd.h>
#include <dlfcn.h>
#include <spawn.h>
#include <hex/helpers/utils_macos.hpp>
#include <CoreFoundation/CoreFoundation.h>
#elif defined(OS_WEB)
@@ -354,6 +356,42 @@ namespace hex {
return result;
}
void executeCommandDetach(const std::string &command) {
#if defined(OS_WINDOWS)
STARTUPINFOA si = { };
PROCESS_INFORMATION pi = { };
si.cb = sizeof(si);
DWORD flags = CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW;
std::string cmdCopy = command;
BOOL result = ::CreateProcessA(
nullptr,
cmdCopy.data(),
nullptr,
nullptr,
false,
flags,
nullptr,
nullptr,
&si,
&pi
);
if (result) {
::CloseHandle(pi.hProcess);
::CloseHandle(pi.hThread);
}
#elif defined(OS_MACOS) || defined(OS_LINUX)
pid_t pid;
const char* argv[] = { "sh", "-c", command.c_str(), nullptr };
::posix_spawnp(&pid, "sh", nullptr, nullptr, const_cast<char* const*>(argv), nullptr);
#elif defined(OS_WEB)
std::ignore = command;
#endif
}
void openWebpage(std::string url) {
if (!url.contains("://"))
url = "https://" + url;