mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-27 23:37:05 -05:00
fix: Make sure updater properly exists after launching update process
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -151,7 +151,10 @@ auto updateCommand(std::string command) {
|
||||
const auto formattedCommand = fmt::format(fmt::runtime(command), updatePath.string());
|
||||
|
||||
hex::log::info("Starting update process with command: '{}'", formattedCommand);
|
||||
return hex::executeCommand(formattedCommand) == 0;
|
||||
|
||||
hex::executeCommandDetach(formattedCommand);
|
||||
|
||||
return 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user