impr: Display background scripts in about page
This commit is contained in:
parent
89f360d1a7
commit
8a3739ee1c
@ -131,8 +131,8 @@ void* PluginSubCommandsFunctionHelper<T>::getSubCommands() {
|
|||||||
std::vector<hex::SubCommand> g_subCommands
|
std::vector<hex::SubCommand> g_subCommands
|
||||||
|
|
||||||
#define IMHEX_FEATURE_ENABLED(feature) WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(IMHEX_PLUGIN_, IMHEX_PLUGIN_NAME), _FEATURE_), feature)
|
#define IMHEX_FEATURE_ENABLED(feature) WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(WOLV_TOKEN_CONCAT(IMHEX_PLUGIN_, IMHEX_PLUGIN_NAME), _FEATURE_), feature)
|
||||||
#define IMHEX_PLUGIN_FEATURES() IMHEX_PLUGIN_FEATURES_IMPL()
|
#define IMHEX_DEFINE_PLUGIN_FEATURES() IMHEX_DEFINE_PLUGIN_FEATURES_IMPL()
|
||||||
#define IMHEX_PLUGIN_FEATURES_IMPL() \
|
#define IMHEX_DEFINE_PLUGIN_FEATURES_IMPL() \
|
||||||
extern std::vector<hex::Feature> g_features; \
|
extern std::vector<hex::Feature> g_features; \
|
||||||
template<> \
|
template<> \
|
||||||
struct PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation> { \
|
struct PluginFeatureFunctionHelper<PluginFunctionHelperInstantiation> { \
|
||||||
@ -142,3 +142,5 @@ void* PluginSubCommandsFunctionHelper<T>::getSubCommands() {
|
|||||||
return &g_features; \
|
return &g_features; \
|
||||||
} \
|
} \
|
||||||
std::vector<hex::Feature> g_features
|
std::vector<hex::Feature> g_features
|
||||||
|
|
||||||
|
#define IMHEX_PLUGIN_FEATURES g_features
|
||||||
|
@ -14,7 +14,7 @@ namespace hex::plugin::decompress {
|
|||||||
using namespace hex;
|
using namespace hex;
|
||||||
using namespace hex::plugin::decompress;
|
using namespace hex::plugin::decompress;
|
||||||
|
|
||||||
IMHEX_PLUGIN_FEATURES() {
|
IMHEX_DEFINE_PLUGIN_FEATURES() {
|
||||||
{ "bzip2 Support", IMHEX_FEATURE_ENABLED(BZIP2) },
|
{ "bzip2 Support", IMHEX_FEATURE_ENABLED(BZIP2) },
|
||||||
{ "zlib Support", IMHEX_FEATURE_ENABLED(ZLIB) },
|
{ "zlib Support", IMHEX_FEATURE_ENABLED(ZLIB) },
|
||||||
{ "LZMA Support", IMHEX_FEATURE_ENABLED(LIBLZMA) },
|
{ "LZMA Support", IMHEX_FEATURE_ENABLED(LIBLZMA) },
|
||||||
|
@ -8,6 +8,7 @@ namespace hex::script::loader {
|
|||||||
|
|
||||||
struct Script {
|
struct Script {
|
||||||
std::string name;
|
std::string name;
|
||||||
|
bool background;
|
||||||
std::function<void()> entryPoint;
|
std::function<void()> entryPoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -19,8 +20,8 @@ namespace hex::script::loader {
|
|||||||
virtual bool initialize() = 0;
|
virtual bool initialize() = 0;
|
||||||
virtual bool loadAll() = 0;
|
virtual bool loadAll() = 0;
|
||||||
|
|
||||||
void addScript(std::string name, std::function<void()> entryPoint) {
|
void addScript(std::string name, bool background, std::function<void()> entryPoint) {
|
||||||
m_scripts.emplace_back(std::move(name), std::move(entryPoint));
|
m_scripts.emplace_back(std::move(name), background, std::move(entryPoint));
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto& getScripts() const {
|
const auto& getScripts() const {
|
||||||
|
@ -262,13 +262,15 @@ namespace hex::script::loader {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (m_methodExists("Main", scriptPath)) {
|
if (m_methodExists("Main", scriptPath)) {
|
||||||
this->addScript(entry.path().stem().string(), [this, scriptPath] {
|
this->addScript(entry.path().stem().string(), false, [this, scriptPath] {
|
||||||
hex::unused(m_runMethod("Main", false, scriptPath));
|
hex::unused(m_runMethod("Main", false, scriptPath));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_methodExists("OnLoad", scriptPath)) {
|
if (m_methodExists("OnLoad", scriptPath)) {
|
||||||
hex::unused(m_runMethod("OnLoad", true, scriptPath));
|
this->addScript(entry.path().stem().string(), true, [this, scriptPath] {
|
||||||
|
hex::unused(m_runMethod("OnLoad", true, scriptPath));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include <fonts/codicons_font.h>
|
||||||
#include <hex/plugin.hpp>
|
#include <hex/plugin.hpp>
|
||||||
#include <hex/api/content_registry.hpp>
|
#include <hex/api/content_registry.hpp>
|
||||||
#include <hex/api/task_manager.hpp>
|
#include <hex/api/task_manager.hpp>
|
||||||
@ -20,6 +21,8 @@ using ScriptLoaders = std::tuple<
|
|||||||
#endif
|
#endif
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
IMHEX_DEFINE_PLUGIN_FEATURES(){ };
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
ScriptLoaders s_loaders;
|
ScriptLoaders s_loaders;
|
||||||
@ -32,17 +35,29 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<const Script*> loadAllScripts() {
|
std::vector<const Script*> loadAllScripts() {
|
||||||
std::vector<const Script*> plugins;
|
std::vector<const Script*> scripts;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::apply([&plugins](auto&&... args) {
|
std::apply([&scripts](auto&&... args) {
|
||||||
(loadScript(plugins, args), ...);
|
(loadScript(scripts, args), ...);
|
||||||
}, s_loaders);
|
}, s_loaders);
|
||||||
} catch (const std::exception &e) {
|
} catch (const std::exception &e) {
|
||||||
log::error("Error when loading scripts: {}", e.what());
|
log::error("Error when loading scripts: {}", e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
return plugins;
|
{
|
||||||
|
std::vector<hex::Feature> features;
|
||||||
|
for (const auto &script : scripts) {
|
||||||
|
if (!script->background)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
features.emplace_back(script->name, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
IMHEX_PLUGIN_FEATURES = features;
|
||||||
|
}
|
||||||
|
|
||||||
|
return scripts;
|
||||||
}
|
}
|
||||||
|
|
||||||
void initializeLoader(u32 &count, auto &loader) {
|
void initializeLoader(u32 &count, auto &loader) {
|
||||||
@ -74,7 +89,7 @@ namespace {
|
|||||||
hex::ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.extras" }, 5000, [] {
|
hex::ContentRegistry::Interface::addMenuItemSubMenu({ "hex.builtin.menu.extras" }, 5000, [] {
|
||||||
static bool menuJustOpened = true;
|
static bool menuJustOpened = true;
|
||||||
|
|
||||||
if (ImGui::BeginMenu("hex.script_loader.menu.run_script"_lang)) {
|
if (ImGui::BeginMenuEx("hex.script_loader.menu.run_script"_lang, ICON_VS_LIBRARY)) {
|
||||||
if (menuJustOpened) {
|
if (menuJustOpened) {
|
||||||
menuJustOpened = false;
|
menuJustOpened = false;
|
||||||
if (!updaterTask.isRunning()) {
|
if (!updaterTask.isRunning()) {
|
||||||
@ -91,7 +106,9 @@ namespace {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const auto &script : scripts) {
|
for (const auto &script : scripts) {
|
||||||
const auto &[name, entryPoint] = *script;
|
const auto &[name, background, entryPoint] = *script;
|
||||||
|
if (background)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (ImGui::MenuItem(name.c_str())) {
|
if (ImGui::MenuItem(name.c_str())) {
|
||||||
runnerTask = TaskManager::createTask("Running script...", TaskManager::NoProgress, [entryPoint](auto&) {
|
runnerTask = TaskManager::createTask("Running script...", TaskManager::NoProgress, [entryPoint](auto&) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user