impr: Don't show crash popup when sending ^C to command line

This commit is contained in:
WerWolv
2025-12-26 21:33:06 +01:00
parent 88c37bb7d9
commit d6d70ca076
3 changed files with 15 additions and 5 deletions

View File

@@ -1,7 +1,12 @@
#pragma once #pragma once
#include <string>
namespace hex::crash { namespace hex::crash {
using CrashCallback = void (*) (const std::string&);
void setCrashCallback(CrashCallback callback);
void setupCrashHandlers(); void setupCrashHandlers();
} }

View File

@@ -1,3 +1,5 @@
#include <crash_handlers.hpp>
#include <hex/api/project_file_manager.hpp> #include <hex/api/project_file_manager.hpp>
#include <hex/api/task_manager.hpp> #include <hex/api/task_manager.hpp>
#include <hex/api/workspace_manager.hpp> #include <hex/api/workspace_manager.hpp>
@@ -46,8 +48,11 @@ namespace hex::crash {
// Function that decides what should happen on a crash // Function that decides what should happen on a crash
// (either sending a message or saving a crash file, depending on when the crash occurred) // (either sending a message or saving a crash file, depending on when the crash occurred)
using CrashCallback = void (*) (const std::string&); static CrashCallback s_crashCallback = sendNativeMessage;
static CrashCallback crashCallback = sendNativeMessage;
void setCrashCallback(CrashCallback callback) {
s_crashCallback = std::move(callback);
}
static std::fs::path s_crashBackupPath; static std::fs::path s_crashBackupPath;
static void saveCrashFile(const std::string& message) { static void saveCrashFile(const std::string& message) {
@@ -74,7 +79,7 @@ namespace hex::crash {
static void callCrashHandlers(const std::string &msg) { static void callCrashHandlers(const std::string &msg) {
// Call the crash callback // Call the crash callback
crashCallback(msg); s_crashCallback(msg);
// Print the stacktrace to the console or log file // Print the stacktrace to the console or log file
dbg::printStackTrace(trace::getStackTrace()); dbg::printStackTrace(trace::getStackTrace());
@@ -213,7 +218,6 @@ namespace hex::crash {
HANDLE_SIGNAL(SIGILL); HANDLE_SIGNAL(SIGILL);
HANDLE_SIGNAL(SIGABRT); HANDLE_SIGNAL(SIGABRT);
HANDLE_SIGNAL(SIGFPE); HANDLE_SIGNAL(SIGFPE);
HANDLE_SIGNAL(SIGINT);
#if defined (SIGBUS) #if defined (SIGBUS)
HANDLE_SIGNAL(SIGBUS); HANDLE_SIGNAL(SIGBUS);
@@ -250,7 +254,7 @@ namespace hex::crash {
// Change the crash callback when ImHex has finished startup // Change the crash callback when ImHex has finished startup
EventImHexStartupFinished::subscribe([]{ EventImHexStartupFinished::subscribe([]{
crashCallback = saveCrashFile; setCrashCallback(saveCrashFile);
}); });
} }

View File

@@ -53,6 +53,7 @@ int main(int argc, char **argv) {
// Handle command line arguments if any have been passed // Handle command line arguments if any have been passed
if (argc > 1) { if (argc > 1) {
crash::setCrashCallback([](auto){});
init::runCommandLine(argc, argv); init::runCommandLine(argc, argv);
} }