mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-28 07:47:03 -05:00
fix: ImHex being displayed as "Main" in some task managers on Linux
This commit is contained in:
@@ -211,7 +211,19 @@ EXPORT_MODULE namespace hex {
|
||||
* @brief Gets the name of the current thread
|
||||
* @return Name of the thread
|
||||
*/
|
||||
static std::string getCurrentThreadName();
|
||||
static std::string_view getCurrentThreadName();
|
||||
|
||||
/**
|
||||
* @brief Sets the ID of the main thread
|
||||
* @param threadId ID of the main thread
|
||||
*/
|
||||
static void setMainThreadId(std::thread::id threadId);
|
||||
|
||||
/**
|
||||
* @brief Checks if the current thread is the main thread
|
||||
* @return True if the current thread is the main thread, false otherwise
|
||||
*/
|
||||
static bool isMainThread();
|
||||
|
||||
/**
|
||||
* @brief Cleans up finished tasks
|
||||
|
||||
@@ -59,6 +59,7 @@ namespace hex {
|
||||
|
||||
thread_local std::array<char, 256> s_currentThreadName;
|
||||
thread_local Task* s_currentTask = nullptr;
|
||||
std::thread::id s_mainThreadId;
|
||||
|
||||
}
|
||||
|
||||
@@ -526,8 +527,19 @@ namespace hex {
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string TaskManager::getCurrentThreadName() {
|
||||
return s_currentThreadName.data();
|
||||
std::string_view TaskManager::getCurrentThreadName() {
|
||||
if (TaskManager::isMainThread())
|
||||
return "Main";
|
||||
else
|
||||
return s_currentThreadName.data();
|
||||
}
|
||||
|
||||
void TaskManager::setMainThreadId(std::thread::id threadId) {
|
||||
s_mainThreadId = threadId;
|
||||
}
|
||||
|
||||
bool TaskManager::isMainThread() {
|
||||
return s_mainThreadId == std::this_thread::get_id();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -29,8 +29,12 @@ int main(int argc, char **argv) {
|
||||
|
||||
std::setlocale(LC_ALL, "en_US.utf8");
|
||||
|
||||
// Set the main thread's name to "Main"
|
||||
TaskManager::setCurrentThreadName("Main");
|
||||
// Tell the Task Manager that we are the main thread
|
||||
TaskManager::setMainThreadId(std::this_thread::get_id());
|
||||
|
||||
// Set the main thread's name. This is the name that will be displayed
|
||||
// in tools like btop
|
||||
TaskManager::setCurrentThreadName("ImHex 🔍");
|
||||
|
||||
// Setup crash handlers right away to catch crashes as early as possible
|
||||
crash::setupCrashHandlers();
|
||||
|
||||
Reference in New Issue
Block a user