diff --git a/main/gui/include/init/splash_window.hpp b/main/gui/include/init/splash_window.hpp index 40bf19111..466515843 100644 --- a/main/gui/include/init/splash_window.hpp +++ b/main/gui/include/init/splash_window.hpp @@ -21,6 +21,7 @@ namespace hex::init { std::string name; std::function callback; bool async; + bool running; }; enum FrameResult{ Success, Failure, Running }; diff --git a/main/gui/source/init/run/common.cpp b/main/gui/source/init/run/common.cpp index e08de028e..f8eb81233 100644 --- a/main/gui/source/init/run/common.cpp +++ b/main/gui/source/init/run/common.cpp @@ -27,7 +27,7 @@ namespace hex::init { // Add initialization tasks to run TaskManager::init(); - for (const auto &[name, task, async] : init::getInitTasks()) + for (const auto &[name, task, async, running] : init::getInitTasks()) splashWindow->addStartupTask(name, task, async); splashWindow->startStartupTasks(); diff --git a/main/gui/source/init/splash_window.cpp b/main/gui/source/init/splash_window.cpp index 54aa97f60..3bffbf175 100644 --- a/main/gui/source/init/splash_window.cpp +++ b/main/gui/source/init/splash_window.cpp @@ -60,7 +60,7 @@ namespace hex::init { } RequestAddInitTask::subscribe([this](const std::string& name, bool async, const TaskFunction &function){ - m_tasks.push_back(Task{ name, function, async }); + m_tasks.push_back(Task{ name, function, async, false }); }); } @@ -220,14 +220,17 @@ namespace hex::init { auto startTime = std::chrono::high_resolution_clock::now(); - // Loop over all registered init tasks - for (auto it = m_tasks.begin(); it != m_tasks.end(); ++it) { - // Construct a new task callback - this->createTask(*it); - } - // Check every 100ms if all tasks have run while (true) { + // Loop over all registered init tasks + for (auto it = m_tasks.begin(); it != m_tasks.end(); ++it) { + // Construct a new task callback + if (!it->running) { + this->createTask(*it); + it->running = true; + } + } + { std::scoped_lock lock(m_tasksMutex); if (m_completedTaskCount >= m_totalTaskCount) diff --git a/main/gui/source/init/tasks.cpp b/main/gui/source/init/tasks.cpp index 95f43e839..d9bcc7ecb 100644 --- a/main/gui/source/init/tasks.cpp +++ b/main/gui/source/init/tasks.cpp @@ -251,7 +251,7 @@ namespace hex::init { // Run all exit tasks, and print to console void runExitTasks() { - for (const auto &[name, task, async] : init::getExitTasks()) { + for (const auto &[name, task, async, running] : init::getExitTasks()) { const bool result = task(); log::info("Exit task '{0}' finished {1}", name, result ? "successfully" : "unsuccessfully"); } @@ -259,18 +259,18 @@ namespace hex::init { std::vector getInitTasks() { return { - { "Setting up environment", setupEnvironment, false }, - { "Creating directories", createDirectories, false }, - { "Loading settings", loadSettings, false }, - { "Loading plugins", loadPlugins, false }, + { "Setting up environment", setupEnvironment, false, false }, + { "Creating directories", createDirectories, false, false }, + { "Loading settings", loadSettings, false, false }, + { "Loading plugins", loadPlugins, false, false }, }; } std::vector getExitTasks() { return { - { "Prepare exit", prepareExit, false }, - { "Unloading plugins", unloadPlugins, false }, - { "Deleting old files", deleteOldFiles, false }, + { "Prepare exit", prepareExit, false, false }, + { "Unloading plugins", unloadPlugins, false, false }, + { "Deleting old files", deleteOldFiles, false, false }, }; }